by zzzcpan · 7y ago · 0 comments
No thanks.
Edit: I just remembered that in cooperative multitasking, it's probably possible for the OS to safely save the program stack pointer, meaning the program doesn't have to unwind its stack when yielding, unlike async programs. Never mind, that makes the two models quite different. However, in practice, programs written for cooperative multitasking really should be structured just like async programs in order to be responsive (so users can, for example, interact with the GUI while downloading files in the background.)
As far as I understand, cooperative is far more efficient than preemptive, but unsuitable for poorly written or untrusted code.
I wish to learn and would really appreciate your assistance if you are willing to help.
Well..
await new Promise((res, rej) => { setImmediate(res); })
(In environments without `setImmediate` this is easily shimmed - https://github.com/YuzuJS/setImmediate)