4 ms·
I guess one of the applications of Coroutines could be WebAssembly. When you run WebAssembly on a website which needs 100% of the CPU for more than a few ms, yo
by s-macke 8y ago
I guess one of the applications of Coroutines could be WebAssembly. When you run WebAssembly on a website which needs 100% of the CPU for more than a few ms, you have to use the "setTimeout(fn, 0)" trick to prevent the "this website stopped responding" message. That means you have to store the current state at some point and continue in the function fn (after waiting 0 ms). Languages which support coroutines out of the box would help a lot here.
- tangent128 8y agoAren't Web Workers (which can run WASM) supposed to fill that role?
- s-macke 8y agoThe web worker helps a little bit. You can send data to the UI thread whenever you want. However on the receiving side you have the same problem. The web worker only receives data when it is idle. For example if you want to send key presses to the web worker, the web worker has to idle. The utilization of the CPU to 100% with simultaneous responsiveness is quite difficult to implement. Actually you have to play an endless game of message ping pong so that the message queue is always filled.