Fork me on GitHub

I have to say the “Hello flow” docs are somehow a bit over my head so I hope you don’t mind me asking more questions here haha 😄


So with everything being async how do I “consume” a flow? Like e.g. watching for a specific event and then calling something once it occurred. I understood that m/reduce can turn a flow into a task but I’m not sure where to go from here.


Also I’m trying to get some basic stuff going in a CLJS REPL and this is failing:

 (m/sp (js/console.log "1")
       (m/? (m/sleep 500))
       (js/console.log "1")))
Despite it being the same as the example here (?)


to run a task in clojurescript, you can call it as a function of two arguments, the success callback and the failure callback


you can even pass it to the promise constructor if you don't need cancellation


m/? outside of sp / ap works only on JVM because it blocks the thread


Ok, got something working 🎉 posting here for posterity:

(defn run-task [t]
   (-> (js/Promise. t)
       (p/then #(js/console.log "done" %))
       (p/catch #(js/console.log "err" %))))

 (->> (m/observe
       (fn [emit!]
         (.onSnapshot (firebase/->ref [:groups gid])
                      (fn [v]
                        (js/console.log "emit! called")
                        (emit! v)))))
      (m/eduction (comp (take 2) (map #(select-keys (firebase/doc %) [:bla]))))
      (m/reduce conj [])


the way you can use transducers is kind of cool


Promesa supports cancellation to some extent, would that mean that there could be an identical API for promesa promises and missionary tasks?


Also on cancellation in general — how would I cancel this task/flow if I no longer need it (e.g. the component using it unmounted or similar)


when you call a task it returns a zero-argument function which cancels the pending process


this API feels very much made for React hooks


well, this surely is a pure coincidence


not complaining 😅


When processing a flow, how can I make it just return a single value instead of a seq? Do I do that via the task?


could you elaborate the use case ?


Waiting for a specific event and wanting to return that event instead of a list with just that one event


m/reduce with a reducing function that returns a reduced on the specific event


nice! guess I could have come up with that myself haha 😅 thanks for your quick help though, missionary is quite fun 🙂


for posterity

(->> (m/eduction (comp (drop-while #(not (pred %))) (take 1)))
     (m/reduce #(reduced %2))))


When cancelling a task the success callback is called, is there a way to know that it was cancelled? (not sure I need this but just curious)


not in the general case. the contract just says a cancelled process must terminate asap, it's up to the task implementation to define its behavior in reaction to the cancellation signal.


@leonoel I discovered Missionary just this week, due to @mjmeintjes and @dustingetz and I have to say it is fascinating but a bit mind-bending for someone not used to RxJava etc. It took me about an hour of playing with the debounce/`clock` example in the REPL with a bunch of println calls added before I actually understood what it was really doing! 🤯 You have a big notice on the repo that Missionary is "Experimental status, breaking changes should be expected." and I saw Dustin's tweet that HyperFiddle's Photon is going to be built on top of Missionary so that makes me wonder: is Missionary actually safe/ready to use in a production codebase? Is it anywhere close to a stable API at this point?


@seancorfield Thank you for your interest ! Missionary is definitely close to a stable API. I haven't found any major flaw in current design after 2 years of extensive use, the latest breaking change was renaming a bunch of operators so at this point I would consider future breakages very unlikely. The only feature I still consider slightly experimental is the reactor, however it's under heavy testing right now and the results are very promising so I'm highly confident switching to a production release policy in the near future.

☺️ 7

That's very encouraging, thank you @leonoel I will spend more time looking at it then...