running regular coroutines in async workers doesn't work properly
Here the coroutine is being resumed inside the async
task:
(let [p (async.promise)
f #(do
(async #(do
(async.sleep 1000)
(async.deliver p 228)))
(async.await p))
c (coroutine.create f)]
(async #(print (coroutine.resume c)))
(print (async.await p))
(coroutine.resume c))
;; true park: 0x561303911980
;; 228
;; true 228
Coroutine can still be resumed because the original yield wasn't from the coroutine itself but from the (async.await p)
in the coroutine.
If the coroutine is resumed on the main thread the behavior is correct:
(let [p (async.promise)
f #(do
(async #(do
(async.sleep 1000)
(async.deliver p 228)))
(async.await p))
c (coroutine.create f)]
(print (coroutine.resume c))
(print (async.await p))
(coroutine.resume c))
;; true 228
;; 228
;; false "cannot resume dead coroutine"
Coroutine correctly waits for the promise.