So this looks like dynamically scoped callbacks. Instead of passing callbacks along as parameters they are declared as “handlers”, and any function down the call stack can invoke them. Is this a correct understanding?
So this looks like dynamically scoped callbacks. Instead of passing callbacks along as parameters they are declared as “handlers”, and any function down the call stack can invoke them. Is this a correct understanding?
That's what I was thinking. You could get almost all of this pretty directly in Javascript by putting a callback function in an AsyncLocalStorage instance or, in other languages, in a thread local variable.
You need more than that for the example with setTimeout(). It requires to be able to freeze the stack and then go back later.
You need stackful coroutine (like goroutine) for that.
That's very interesting, thanks! It gave me a brainwave and I wondered I could implement that in Bluefin. I'm pretty sure Bluefin's Request[1] is a second class stackful coroutine, and sure enough it turns out to be possible, so I'm pleased about that.
Or in Lua you'd wrap the initial call in a coroutine, possibly with coronest[a] or something similar to make handling the effects at the right layer easier.
And so then the outer code is a loop around coroutine.resume, and the inner code uses coroutine.yield to perform an effect.
[a]: https://github.com/saucisson/lua-coronest
Yes. dynamically scoped, and statically typed.
How can it be statically typed in JavaScript?