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

after hook is called early #8

Open
joebowbeer opened this issue Oct 3, 2019 · 2 comments
Open

after hook is called early #8

joebowbeer opened this issue Oct 3, 2019 · 2 comments

Comments

@joebowbeer
Copy link

I notice that in most cases wrapCallback is passed a function that eventually calls a callback, not the callback itself. So in most cases the init/before/after async hooks will be called in rapid-fire, and will not capture the lifetime of the hooked mongo operation. The after hook shouldn't fire until after the callback (cb) is called:

https://github.com/Automattic/mongoose/blob/master/lib/model.js#L453

@vkarpov15
Copy link
Member

@joebowbeer can you please clarify what you mean with some code samples? I'm not sure I understand.

@joebowbeer
Copy link
Author

joebowbeer commented Oct 7, 2019

It becomes clearer if middleware pre and post hooks are added to the test. (I will do that soon.)

With pre and post hooks connected, the sequence is init/before/after/pre/post - and eventually destroy when garbage collected.

The expected sequence is init/before/pre/post/after or init/pre/before/after/post.

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