| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f734b3e commit f7f1437
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,22 @@ inline double AsyncWrap::get_trigger_async_id() const { | |||
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | + inline AsyncWrap::AsyncScope::AsyncScope(AsyncWrap* wrap) | ||
| 49 | + : wrap_(wrap) { | ||
| 50 | + Environment* env = wrap->env(); | ||
| 51 | + if (env->async_hooks()->fields()[Environment::AsyncHooks::kBefore] == 0) | ||
| 52 | + return; | ||
| 53 | + EmitBefore(env, wrap->get_async_id()); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + inline AsyncWrap::AsyncScope::~AsyncScope() { | ||
| 57 | + Environment* env = wrap_->env(); | ||
| 58 | + if (env->async_hooks()->fields()[Environment::AsyncHooks::kAfter] == 0) | ||
| 59 | + return; | ||
| 60 | + EmitAfter(env, wrap_->get_async_id()); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + | ||
| 48 | 64 | inline v8::MaybeLocal<v8::Value> AsyncWrap::MakeCallback( | |
| 49 | 65 | const v8::Local<v8::String> symbol, | |
| 50 | 66 | int argc, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,6 +169,18 @@ class AsyncWrap : public BaseObject { | |||
| 169 | 169 | ||
| 170 | 170 | static void WeakCallback(const v8::WeakCallbackInfo<DestroyParam> &info); | |
| 171 | 171 | ||
| 172 | + // This is a simplified version of InternalCallbackScope that only runs | ||
| 173 | + // the `before` and `after` hooks. Only use it when not actually calling | ||
| 174 | + // back into JS; otherwise, use InternalCallbackScope. | ||
| 175 | + class AsyncScope { | ||
| 176 | + public: | ||
| 177 | + explicit inline AsyncScope(AsyncWrap* wrap); | ||
| 178 | + ~AsyncScope(); | ||
| 179 | + | ||
| 180 | + private: | ||
| 181 | + AsyncWrap* wrap_ = nullptr; | ||
| 182 | + }; | ||
| 183 | + | ||
| 172 | 184 | private: | |
| 173 | 185 | friend class PromiseWrap; | |
| 174 | 186 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments