4

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 :

  • take items from this future
  • know also how many items I can take at once (if several are waiting)

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

nha
  • 17,623
  • 13
  • 87
  • 133

1 Answers1

5

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

Daniel Compton
  • 13,878
  • 4
  • 40
  • 60