nha
nha

Reputation: 18005

Clojure RethinkDB subscribe to a changefeed

I am using the Clojure driver for RethinkDB. I want to get change feeds from a query. Here is what I have so far :

(defn change-feed [conn]
  (loop [changes (future
                   (-> (r/db "mydb")
                       (r/table "mytable")
                       r/changes
                       (r/run conn)))]
    (println "date : " ((comp :name :newval) first @changes)) ;;prints nil
    (recur (rest changes))))

It blocks in my REPL when called (which is normal). I then add data using the RethinkDB interface. It prints nil and I get the following error :

IllegalArgumentException Don't know how to create ISeq from: clojure.core$future_call$reify__6736  clojure.lang.RT.seqFrom (RT.java:528)

What am I doing wrong ? I would like to be able to :

Note : I plan to use manifold to manipulate the result in the end, so any solution using it is completely fine.

Upvotes: 4

Views: 344

Answers (1)

Daniel Compton
Daniel Compton

Reputation: 14569

I don't think you need the future block there, the Cursor returned by the clj-rethinkdb library will block until it's ready.

You could also use a doseq instead of a loop which might be more natural.

I'm a maintainer of clj-rethinkdb, and we've got changes coming down the pipe to present a core.async interface and a new Cursor abstraction. If you want to use it early, checkout https://github.com/apa512/clj-rethinkdb/pull/55

Upvotes: 5

Related Questions