Calling a Signal after a SendProgress should not clear progress data
| 301 | |
| 302 | // Calling a Signal after a SendProgress should not clear progress data |
| 303 | class SignalAfterProgressTestWorker : public AsyncProgressWorker<ProgressData> { |
| 304 | public: |
| 305 | static void DoWork(const CallbackInfo& info) { |
| 306 | Function cb = info[0].As<Function>(); |
| 307 | Function progress = info[1].As<Function>(); |
| 308 | |
| 309 | SignalAfterProgressTestWorker* worker = new SignalAfterProgressTestWorker( |
| 310 | cb, progress, "TestResource", Object::New(info.Env())); |
| 311 | worker->Queue(); |
| 312 | } |
| 313 | |
| 314 | protected: |
| 315 | void Execute(const ExecutionProgress& progress) override { |
| 316 | ProgressData data{0}; |
| 317 | progress.Send(&data, 1); |
| 318 | progress.Signal(); |
| 319 | } |
| 320 | |
| 321 | void OnProgress(const ProgressData* /* data */, size_t count) override { |
| 322 | Napi::Env env = Env(); |
| 323 | bool error = false; |
| 324 | Napi::String reason = Napi::String::New(env, "No error"); |
| 325 | if (count != 1) { |
| 326 | error = true; |
| 327 | reason = Napi::String::New(env, "expect 1 count of data"); |
| 328 | } |
| 329 | _progress.MakeCallback(Receiver().Value(), |
| 330 | {Napi::Boolean::New(env, error), reason}); |
| 331 | } |
| 332 | |
| 333 | private: |
| 334 | SignalAfterProgressTestWorker(Function cb, |
| 335 | Function progress, |
| 336 | const char* resource_name, |
| 337 | const Object& resource) |
| 338 | : AsyncProgressWorker(cb, resource_name, resource) { |
| 339 | _progress.Reset(progress, 1); |
| 340 | } |
| 341 | FunctionReference _progress; |
| 342 | }; |
| 343 | } // namespace |
| 344 | |
| 345 | Object InitAsyncProgressWorker(Env env) { |
nothing calls this directly
no outgoing calls
no test coverage detected