MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / DoWork

Method DoWork

test/async_worker.cc:278–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276 ~CancelWorker() {}
277
278 static void DoWork(const CallbackInfo& info) {
279 Function cb = info[0].As<Function>();
280 std::string echo = info[1].As<String>();
281 int threadNum = info[2].As<Number>().Uint32Value();
282
283 for (int i = 0; i < threadNum; i++) {
284 AsyncWorker* worker = new EchoWorker(cb, echo);
285 worker->Queue();
286 assert(worker->Env() == info.Env());
287 }
288
289 AsyncWorker* cancelWorker = new CancelWorker(cb);
290 cancelWorker->Queue();
291
292#ifdef NAPI_CPP_EXCEPTIONS
293 try {
294 cancelWorker->Cancel();
295 } catch (Napi::Error&) {
296 Napi::Error::New(info.Env(), "Unable to cancel async worker tasks")
297 .ThrowAsJavaScriptException();
298 }
299#else
300 cancelWorker->Cancel();
301#endif
302 }
303
304 void Execute() override {
305 // Simulate cpu heavy task

Callers

nothing calls this directly

Calls 4

QueueMethod · 0.80
EnvMethod · 0.80
CancelMethod · 0.80

Tested by

no test coverage detected