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

Using promisify on setTimeout causes it to fail #136

Open
ATGardner opened this issue Aug 21, 2018 · 1 comment
Open

Using promisify on setTimeout causes it to fail #136

ATGardner opened this issue Aug 21, 2018 · 1 comment

Comments

@ATGardner
Copy link

I have created a simple test (https://gist.github.com/ATGardner/7c34a90b01ed0bf513ccd6911b4372f3) which shows that when I try to use a promisified setTimeout call, it fails with

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

When using promisify(setTimeout) on the unwrapped, original, setTimeout function, it works just fine.

I understand this is because the original function has a util.promisify.custom field which contains the custom promisified version of it. But the wrapped one does not, and promisify can't automatically wrap a function with a callback as the 1st argument. I guess the solution would be to also create and wrap the util.promisify.custom field of setTimeout in async-listener/index.js (and maybe a more general solution, to other functions as well)

@watson
Copy link
Collaborator

watson commented Aug 26, 2018

Thanks for taking the time to investigate this issue.

Since Node.js version 8, Async Hooks have been part of Node core, which does more or less the same thing as this polyfill module. The util.promisify function was also added in Node 8. If you're using Node 8 or higher I would recommend using Async Hooks instead of this module.

I know this is not an solution to the problem you encountered and it probably is possible fix it in this module. But I don't personally have time to look into it. So I would recommend that you use Async Hooks instead if at all possible. You are of course also more than welcome to open a PR with a fix your self. Then I'm sure my self or one of the other maintainers will review it.

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