Great article! In NodeJS I usually prefer the one-liner version:
const sleep = require('util').promisify(setTimeout);
The docs say it only works if the original function takes the callback as the final argument, setTimeout takes the callback as the first argument. Does this code even work? nodejs.org/dist/latest-v8.x/docs/a...
setTimeout
Functions can define their own promisified version using a symbol, which is what setTimeout does in Node.js
So yes, it works.
That makes sense. Good to know if we're using Node.js
I think it got to be a Node.js style callback with err as the first parameter.
err
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article! In NodeJS I usually prefer the one-liner version:
The docs say it only works if the original function takes the callback as the final argument,
setTimeout
takes the callback as the first argument. Does this code even work? nodejs.org/dist/latest-v8.x/docs/a...Functions can define their own promisified version using a symbol, which is what setTimeout does in Node.js
So yes, it works.
That makes sense. Good to know if we're using Node.js
I think it got to be a Node.js style callback with
err
as the first parameter.