6 ms·
The author here. Just opened HN and saw that my library is on the front page . If you have any questions, I can answer them.
by astoilkov 3y ago
The author here. Just opened HN and saw that my library is on the front page . If you have any questions, I can answer them.
- susi22 3y agoHow does this differ from cooperative multi tasking?
- jerf 3y agoIf I'm reading this correctly, this is a library for use within a browser, in which case the answer is that this makes it easier to live within the constraints of the browser, which has arguably the strangest "multitasking" support anywhere, what with all the constraints it had to satisfy to be added in to an architecture already 15 years old at that point.
- astoilkov 3y agoYeah, that sums it up. The library tries to use the single thread the browser UI is running on and just not freeze it.
- rictic 3y agoHave you benchmarked the overhead of awaiting? I believe that in doing so you yield to the microtask queue and then your function has to be scheduled and run again. You could compare await yieldOrContinue('user-visible'); doSomeWork(); against if (isTimeToYield('user-visible')) { await yieldControl('user-visible'); } doSomeWork(); A few years back when I measured it on a fast laptop the cost was ~1µs to do `await 0;`
- astoilkov 3y agoI haven't. I should do that. Many people are talking about this and this makes me think I should measure and talk about it in the readme. Thanks!
- dnmllr_ 3y agoHi, forgive me if I missed it, I just briefly browsed the repo. Does the library itself handle cancellation, or would user code be responsible for that?
- astoilkov 3y agoThis is on my list. I want to provide a `signal` property to enable easier and more efficient cancellation.