Node.js API compatibility - Timers

The timers module in Node.js provides a set of functions for scheduling the execution of code after a specified delay or at regular intervals. It’s essential for managing asynchronous operations and controlling the timing of function execution within applications.

/**
* An example of using Node.js Timers API in an Azion Edge Function.
* Support:
* - Partially supported (Extended by library `timers-browserify`)
* @module runtime-apis/nodejs/timers/main
* @example
* // Execute with Azion Bundler:
* npx edge-functions build
*
*/
import timers from "node:timers";
/**
* An example of using the Node.js Timers API in an Azion Edge Function.
* @param {*} event
* @returns {Promise<Response>}
*/
const main = async (event) => {
console.log("Hello, world!");
console.log("Waiting for 5 seconds...");
await new Promise((resolve) => timers.setTimeout(resolve, 2000));
return new Response("Done!", { status: 200 });
};
export default main;

Contributors