| 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 |
nothing calls this directly
no test coverage detected