Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-03-07 19:55:24 +0300
committerAnna Henningsen <anna@addaleax.net>2018-03-15 14:53:07 +0300
commitf7f1437d44f3e4b745e36540a752065cc58d993b (patch)
tree39493f25b64da7761cb0fb142c95cb121e3d0f7c /src/async_wrap-inl.h
parentf734b3eb04c0d355ef7ab893ed5869b867d35642 (diff)
src: add helper for before/after scope without JS calls
Add `AsyncScope` for cases where the async_hooks `before` and `after` callbacks should be called, to track async context, but no actual JS is called in between and we can therefore skip things like draining the microtask or `nextTick` queues. PR-URL: https://github.com/nodejs/node/pull/18936 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src/async_wrap-inl.h')
-rw-r--r--src/async_wrap-inl.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/async_wrap-inl.h b/src/async_wrap-inl.h
index 21b1f9cee9f..c9f12333243 100644
--- a/src/async_wrap-inl.h
+++ b/src/async_wrap-inl.h
@@ -45,6 +45,22 @@ inline double AsyncWrap::get_trigger_async_id() const {
}
+inline AsyncWrap::AsyncScope::AsyncScope(AsyncWrap* wrap)
+ : wrap_(wrap) {
+ Environment* env = wrap->env();
+ if (env->async_hooks()->fields()[Environment::AsyncHooks::kBefore] == 0)
+ return;
+ EmitBefore(env, wrap->get_async_id());
+}
+
+inline AsyncWrap::AsyncScope::~AsyncScope() {
+ Environment* env = wrap_->env();
+ if (env->async_hooks()->fields()[Environment::AsyncHooks::kAfter] == 0)
+ return;
+ EmitAfter(env, wrap_->get_async_id());
+}
+
+
inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback(
const v8::Local<v8::String> symbol,
int argc,