3 ms·
Promisify converts a callback based function into a promise returning function [1]. If the function has a `promisify.custom` method, `promisify` will simply ret
by throwitaway1123 2y ago
Promisify converts a callback based function into a promise returning function [1]. If the function has a `promisify.custom` method, `promisify` will simply return the `promisify.custom` method instead of wrapping the original function. Calling `promisify` on `setTimeout` in Node is redundant because Node already ships a built in promisified version of `setTimeout`. So the following is true:
setTimeout[promisify.custom] === require('node:timers/promises').setTimeout
You could of course manually wrap `setTimeout` yourself as well:
const sleep = n => new Promise(resolve => setTimeout(resolve, n))
[1] https://nodejs.org/docs/latest-v22.x/api/util.html#utilpromisifyoriginal https://nodejs.org/docs/latest-v22.x/api/util.html#utilpromi...