Fork me on GitHub
#missionary
<
2021-11-14
>
lostineverland06:11:36

Hey folks, I’ve been looking for alternative ways of handling async code so this caught my attention. The docs suggest that this library works with clojurescript but, in my experience, none of the examples (tutorials) work on the javascript side. I understand that JS has thread limitations, so I’m looking for examples that navigate through these limitations... How do I use this if I’m targeting JS?

leonoel08:11:23

Everything works the same in js except ? outside sp/`ap`, and via. In practice the only difference should be the entry point - run your main task with plain callbacks, or pass it to the promise constructor

lostineverland20:11:34

Hi @leonoel, thanks for your time! So I tried it with my typical callback mechanism the go block, but it still fails:

(ns script.play
  (:require-macros [cljs.core.async.macros :refer [go]])
  (:require [missionary.core :as m]
            [cljs.core.async :refer [<!]]))

(def nap (m/sleep 1000))

(def slowmo-hello-world
  (m/sp (println "Hello")
        (m/? nap)
        (println "World")
        (m/? nap)
        (println "!")))

(go (let [res (<! (m/? slowmo-hello-world))]
      (nil? res)))

lostineverland20:11:46

Am I missing something obvious?

leonoel20:11:04

(def cancel (slowmo-hello-world js/console.log js/console.error))

leonoel20:11:43

(js/Promise. slowmo-hello-world)

leonoel20:11:36

m/? is undefined outside of sp/`ap`

leonoel20:11:02

like <! outside of go, or await outside of async

lostineverland20:11:09

this correlation was super helpful!