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

Function asyncProgressWorkerNoCbOverloads

test/async_progress_worker.js:108–147  ·  view source on GitHub ↗
(bindingFunction)

Source from the content-addressed store, hash-verified

106}
107
108async function asyncProgressWorkerNoCbOverloads (bindingFunction) {
109 bindingFunction(common.mustCall(() => {}));
110 if (!checkAsyncHooks()) {
111 return;
112 }
113 const asyncResources = [
114 { resName: 'noCbResources', resObject: {} },
115 { resName: 'noCbResourcesObject', resObject: { foo: 'bar' } }
116 ];
117
118 for (const asyncResource of asyncResources) {
119 const asyncResName = asyncResource.resName;
120 const asyncResObject = asyncResource.resObject;
121
122 const hooks = common.installAysncHooks(asyncResource.resName);
123 const triggerAsyncId = asyncHooks.executionAsyncId();
124 await new Promise((resolve, reject) => {
125 if (Object.keys(asyncResObject).length === 0) {
126 bindingFunction(asyncResName, common.mustCall(() => {}));
127 } else {
128 bindingFunction(asyncResName, asyncResObject, common.mustCall(() => {}));
129 }
130
131 hooks.then(actual => {
132 assert.deepStrictEqual(actual, [
133 {
134 eventName: 'init',
135 type: asyncResName,
136 triggerAsyncId,
137 resource: asyncResObject
138 },
139 { eventName: 'before' },
140 { eventName: 'after' },
141 { eventName: 'destroy' }
142 ]);
143 }).catch(common.mustNotCall());
144 resolve();
145 });
146 }
147}
148
149function success (binding) {
150 return new Promise((resolve, reject) => {

Callers 1

testFunction · 0.70

Calls 1

checkAsyncHooksFunction · 0.70

Tested by 1

testFunction · 0.56