Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pify(setTimeout) does not work correctly in Node.js #56

Closed
feross opened this issue Feb 8, 2018 · 1 comment
Closed

pify(setTimeout) does not work correctly in Node.js #56

feross opened this issue Feb 8, 2018 · 1 comment

Comments

@feross
Copy link

feross commented Feb 8, 2018

This works with util.promisify():

const { promisify } = require('util')
const setTimeoutAsync = promisify(setTimeout)

async function init () {
  console.log('Waiting 5 seconds...')
  await setTimeoutAsync(5000)
  console.log('Done!')
}

init()

It would be nice if it worked with pify() too!

Not sure if this requires using util.promisify() when running in Node.js, as described in #41 or if it can just be implemented by reading the util.promisify.custom symbol on the function, as described in the Node.js docs: https://nodejs.org/api/util.html#util_custom_promisified_functions

@sindresorhus
Copy link
Owner

If you want magic behavior like that, I think it's better to just use util.promisify directly. I mostly use util.promisify these days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants