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

Questions: will nodejs expose SetPromiseHook of V8 as javascript API in the future? #13139

Closed
JiaLiPassion opened this issue May 21, 2017 · 9 comments
Labels
async_hooks Issues and PRs related to the async hooks subsystem. promises Issues and PRs related to ECMAScript promises. question Issues that look for answers.

Comments

@JiaLiPassion
Copy link
Contributor

  • Version:
  • Platform:
  • Subsystem:

in the newest nodejs,

  1. the async_wrap and async_hooks have been implemented in async_hooks initial implementation #11883.
  2. addPromiseHook have been exposed in domain: support promises #12489

I want to ask that will addPromiseHook be exposed as Javascript API? Or it will also use the async_wrap to intercept the promise lifecycle?

The reason I asked is I want to implement an async_hooks version zone.js to resolve the
native async/await issue. currently native async/await of nodejs use native v8 promise and can't be tracked by javascript module.

Thank you!

@addaleax addaleax added async_hooks Issues and PRs related to the async hooks subsystem. promises Issues and PRs related to ECMAScript promises. question Issues that look for answers. labels May 21, 2017
@addaleax
Copy link
Member

I want to ask that will addPromiseHook be exposed as Javascript API?

I don’t think that’s likely, but you can open a PR and see where that goes if you really want.

Or it will also use the async_wrap to intercept the promise lifecycle?

I’m not sure, but maybe #13000 (Promise support for async_hooks) is the answer to your question?

@JiaLiPassion
Copy link
Contributor Author

@addaleax , thank you very much for your reply, I will look into #13000.

@AndreasMadsen
Copy link
Member

@JiaLiPassion Why is async_hooks not sufficient? If you want to implement Zones you will need more than just promise hooks. I can see that zone.js uses async-listener, async_hooks is a core-supported alternative to that and it will support promises.

If you just want the promise part you can filter all events in async_hooks by the provider parameter, the extra overhead should be very small. If async_hooks is not enough and you need more information, then I think that is the best place to start a discussion.

@JiaLiPassion
Copy link
Contributor Author

JiaLiPassion commented May 21, 2017

@AndreasMadsen , thanks for reply, in fact zone.js not use async-listener, it just monkey-patch all native async APIs, such as promise, setTimeout and so on.

Now zone.js monkey-patch those APIs in nodejs.

  1. setTimeout/Immediate/Interval
  2. Promise
  3. EventEmitter
  4. process.nextTick
  5. fs
  6. crypto

https://github.com/angular/zone.js/blob/master/STANDARD-APIS.md

So if async_hooks will support all async APIs, I think it will be ok for re-implement zone.js with the new async_hooks.

I just began to read the document about async_hooks, and I will try to find out how to use it.

If you just want the promise part you can filter all events in async_hooks by the provider parameter, the extra overhead should be very small. If async_hooks is not enough and you need more information, then I think that is the best place to start a discussion.

Thank you for the information, basically I want to use all events with async_hooks, but I may want the provider for some logic, is there any document for this parameter? I didn't find it in here, https://github.com/nodejs/node-eps/blob/master/006-asynchooks-api.md

edit by @AndreasMadsen: fixed quote formatting.

@AndreasMadsen
Copy link
Member

AndreasMadsen commented May 21, 2017

So if async_hooks will support all async APIs, I think it will be ok for re-implement zone.js with the new async_hooks.

if it doesn't it is a bug :)

Thank you for the information, basically I want to use all events with async_hooks, but I may want the provider for some logic, is there any document for this parameter? I didn't find it in here, https://github.com/nodejs/node-eps/blob/master/006-asynchooks-api.md

Sorry, it is now called type it is a parameter in the init hook.

PS: I recommend looking at dprof as a starting example, as it uses most of the async_hooks feature. Note that it currently uses and older API, there is a PR for the new API.

@JiaLiPassion
Copy link
Contributor Author

@AndreasMadsen , thank you very much, I will try to re-implement zone.js with async_hooks.

And the promise support with async_hooks will be implemented until #13000 is merged, is that right?

@AndreasMadsen
Copy link
Member

And the promise support with async_hooks will be implemented until #13000 is merged, is that right?

Yes, you will have to wait on #13000 to get merged before promises are supported by async_hooks. I maintain the async_hooks tracking issue that you can follow: nodejs/diagnostics#29

@JiaLiPassion
Copy link
Contributor Author

@AndreasMadsen , thank you, I will keep track with nodejs/diagnostics#29 and #13000.

@addaleax
Copy link
Member

Cool, I’ll close this as an answered question then. If you have any further questions, feel free to ask here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. promises Issues and PRs related to ECMAScript promises. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants