This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-22
Channels
- # announcements (6)
- # babashka (8)
- # beginners (136)
- # cider (5)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (198)
- # clojure-argentina (4)
- # clojure-australia (1)
- # clojure-europe (25)
- # clojure-italy (4)
- # clojure-nl (5)
- # clojure-poland (1)
- # clojure-spec (4)
- # clojure-uk (4)
- # clojuredesign-podcast (4)
- # clojurescript (36)
- # conjure (11)
- # data-science (1)
- # datomic (6)
- # defnpodcast (1)
- # deps-new (5)
- # emacs (7)
- # events (1)
- # fulcro (10)
- # graalvm (9)
- # graalvm-mobile (10)
- # helix (9)
- # introduce-yourself (1)
- # jackdaw (1)
- # jobs-discuss (5)
- # kaocha (6)
- # lsp (10)
- # malli (11)
- # missionary (28)
- # off-topic (2)
- # pathom (24)
- # pedestal (7)
- # portal (1)
- # re-frame (12)
- # reagent (2)
- # reitit (1)
- # remote-jobs (1)
- # sci (7)
- # shadow-cljs (6)
- # sql (6)
- # tools-deps (10)
- # vim (9)
- # xtdb (19)
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/?
(m/sp (js/console.log "1")
(m/? (m/sleep 500))
(js/console.log "1")))
Despite it being the same as the example here https://cljdoc.org/d/missionary/missionary/b.20/doc/readme/tutorials/hello-task#sequential-composition (?)to run a task in clojurescript, you can call it as a function of two arguments, the success callback and the failure callback
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 [])
(run-task))
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? https://github.com/funcool/promesa/blob/30d10ff3403675e131eb50b3ed6403c8e2acbbd2/src/promesa/impl.cljc
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
ah neat
this API feels very much made for React hooks
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?
Waiting for a specific event and wanting to return that event instead of a list with just that one 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.
gotcha
@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.
That's very encouraging, thank you @leonoel I will spend more time looking at it then...