Description
(This may end up being more of a thought experiment, please feel free to close this issue)
JSPI is supposed to be the spiritual successor to asyncify, which tinygo currently uses for scheduling on GOOS=JS. At a high level (from my understanding) JSPI essentially provides some form of constrained stack switching (e.g. cannot suspend JS frames).
Out of curiosity and with my (very) limited knowledge of how tinygo or JSPI works, I took a shot at this and got some a basic Go program with goroutines to work without asyncify on Chrome. In my implementation,
- Each goroutine is a separate stack
Pause
suspends the stack and puts the promise in a global mapResume
suspends the current stack and resolves the promise, reverting back to the old goroutine- After suspending the stack, the scheduler is invoked directly. If there is no more work, a trap gets rid of the stack.
If anyone is curious - here's where I stopped
pulsejet@28c1d8d
I think (with my limited knowledge) it's hard to say which approach is faster (unwind-rewind, or a JS call for each scheduler event), so it might make sense to run some benchmarks first.
As the first line says, please close if this is a stupid idea.