-
Notifications
You must be signed in to change notification settings - Fork 194
Open
Labels
Milestone
Description
Code from "Structured Asynchrony with Algebraic Effects":
import std/num/int32
fun main()
with async-handle
with handler
ctl throw_(s: string)
throw(s)
println("before wait")
wait(0.i32)
println("after wait")
alias result<a> = either<string, a>
effect async
ctl await(initiate: (result<a> -> io ()) -> io ()): result<a>
val async-handle = handler
ctl await(initiate)
initiate(resume)
fun await1(initiate: (a -> io ()) -> io ()): <async, exn_> a
untry_(await(fn(cb)
initiate(fn(x) cb(Right(x)))
))
fun await0(initiate: (() -> io ()) -> io ()): <async, exn_> ()
await1(fn(cb) initiate(fn() cb(())))
fun wait(secs: int32): <async, exn_> ()
await0 fn(cb)
set-timeout(cb, secs * 1000.i32)
()
alias timeout-id = int
extern set-timeout(cb: () -> io (), ms: int32): io int
js inline "setTimeout(#1, #2)"
effect exn_
ctl throw_(s: string): a
fun untry_(ex: either<string, a>): <exn_> a
match ex
Left(exn) -> throw_(exn)
Right(x) -> x
Output:
$ node .koka/v3.1.2/js-debug-463762/async__main.mjs
before wait
file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:61
_evv._cfc = ev.hnd._cfc;
^
TypeError: Cannot read properties of undefined (reading 'hnd')
at Object._evv_swap_create1 (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:61:20)
at Module._open_at1 (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:1457:25)
at _mlift_await1_10046 (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/async.mjs:144:24)
at Array.<anonymous> (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/async.mjs:171:14)
at file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:220:21
at open1 (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:1527:11)
at file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:1566:14
at _yield.conts.<computed> (file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:243:41)
at file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:220:21
at file:///home/omer/koka/why-effects/.koka/v3.1.2/js-debug-463762/std_core_hnd.mjs:649:49
Node.js v22.11.0
The error seems to be happening before the setTimeout call. Replacing the inline JS to setTimeout as something invalid like inline js "blah" doesn't change how it fails.