Fork me on GitHub
#missionary
<
2022-10-31
>
Richie19:10:02

TypeError: PromiseResolve called on non-object at resolve (<anonymous>)
How can I lift a promise into a task in Clojurescript? Thanks!

Dustin Getz19:10:03

this succeeds:

Dustin Getz19:10:06

(tests
  (def x (js/Promise.resolve "hi"))
  ((m/sp (tap (m/? (await-promise x))))
   tap tap)
  % := "hi"
  % := "hi")

Dustin Getz19:10:22

Looks like javascript black magic to me violating a cloroutine assumption related to the context of the interop call

Dustin Getz19:10:45

call seems to need Promise.resolve.bind(Promise)

Dustin Getz20:10:42

this passes

(defn f [x]
  (js/Promise.resolve.call js/Promise x))

(tests
  ((m/sp (tap (m/? (await-promise (f "2")))))
   tap tap)
  % := "2"
  % := "2")
this fails
(tests
  ((m/sp (tap (m/? (await-promise (js/Promise.resolve.call js/Promise "3")))))
   tap tap)
  % := "3"
  % := "3")

FAIL in (generated__dustin_scratch_1) (:)
expected: (= % "3")
  actual: (not (= #object[TypeError TypeError: cr48023_place_2.call is not a function] "3"))
so yeah looks to me like cloroutine gets the interop wrong

Richie20:10:54

This is usable, thanks!

leonoel10:11:34

indeed this is a cloroutine bug, thanks for reporting https://github.com/leonoel/cloroutine/issues/25