Skip to content

timers: add experimental scheduler api

Adds experimental implementations of the yield and wait APIs being explored at https://github.com/WICG/scheduling-apis.

When I asked the WHATWG folks about the possibility of standardizing the awaitable versions of setTimeout/setImmediate that we have implemented in timers/promises, they pointed at the work in progress scheduling APIs draft as they direction they'll be going. While there is definitely a few thing in that draft that have questionable utility to Node.js, the yield and wait APIs map cleanly to the setImmediate and setTimeout we already have.

const { scheduler } = require('timers/promises');

await scheduler.wait(1000);  // Continue after 1 second

await scheduler.yield();  // Continue after this turn of the event loop

Signed-off-by: James M Snell jasnell@gmail.com

/cc @mcollina

Merge request reports

Loading