Closed ScriptedAlchemy closed 7 months ago
In this specific case calling requestIdleCallback()
and calling yieldControl()
is equivalent and there isn't a benefit in using yieldControl()
.
However, I see that there could be scenarios where you would want to cancel yieldControl()
. This could be done with different tactics that are used when canceling promises. Here's a quick example of how this could be done using AbortSignal
without new features in main-thread-scheduling
:
async function requestDoWork(signal) {
await yieldControl('background')
if (signal.aborted) {
return
}
// do work
}
const controller = new AbortController()
requestDoWork(controller.signal)
// if you want to cancel the work just call controller.abort()
I will be implementing this.
I've implemented a yieldOrContinue(strategy, signal?)
property and published a new release. Any feedback is welcome.
Ive been wanting to use main thread scheduling to time aggressive updates on a function.
So in this case, if i have a update come through, then 1ms later another update is sent, id want to cancel the preexisting scheduled event and reschedule only the last valid call.
I do something like this with idleCallback but was wondering if this library could expose something similar, perhaps a label?
So if "something" already exists, and a new "something" event is sent in, remove the previous one from the queue and push this onto the end instead