MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / test

Function test

test/callbackscope.js:20–49  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

18module.exports = require('./common').runTest(test);
19
20function test (binding) {
21 if (!checkAsyncHooks()) { return; }
22
23 let id;
24 let insideHook = false;
25 const hook = asyncHooks.createHook({
26 init (asyncId, type, triggerAsyncId, resource) {
27 if (id === undefined && (type === 'callback_scope_test' || type === 'existing_callback_scope_test')) {
28 id = asyncId;
29 }
30 },
31 before (asyncId) {
32 if (asyncId === id) { insideHook = true; }
33 },
34 after (asyncId) {
35 if (asyncId === id) { insideHook = false; }
36 }
37 }).enable();
38
39 return new Promise(resolve => {
40 binding.callbackscope.runInCallbackScope(function () {
41 assert(insideHook);
42 binding.callbackscope.runInPreExistingCbScope(function () {
43 assert(insideHook);
44 hook.disable();
45 resolve();
46 });
47 });
48 });
49}

Callers

nothing calls this directly

Calls 1

checkAsyncHooksFunction · 0.70

Tested by

no test coverage detected