| 3261 | |
| 3262 | template <class T> |
| 3263 | class AsyncProgressWorker : public AsyncProgressWorkerBase<void> { |
| 3264 | public: |
| 3265 | virtual ~AsyncProgressWorker(); |
| 3266 | |
| 3267 | class ExecutionProgress { |
| 3268 | friend class AsyncProgressWorker; |
| 3269 | |
| 3270 | public: |
| 3271 | void Signal() const; |
| 3272 | void Send(const T* data, size_t count) const; |
| 3273 | |
| 3274 | private: |
| 3275 | explicit ExecutionProgress(AsyncProgressWorker* worker) : _worker(worker) {} |
| 3276 | AsyncProgressWorker* const _worker; |
| 3277 | }; |
| 3278 | |
| 3279 | void OnWorkProgress(void*) override; |
| 3280 | |
| 3281 | protected: |
| 3282 | explicit AsyncProgressWorker(const Function& callback); |
| 3283 | explicit AsyncProgressWorker(const Function& callback, |
| 3284 | const char* resource_name); |
| 3285 | explicit AsyncProgressWorker(const Function& callback, |
| 3286 | const char* resource_name, |
| 3287 | const Object& resource); |
| 3288 | explicit AsyncProgressWorker(const Object& receiver, |
| 3289 | const Function& callback); |
| 3290 | explicit AsyncProgressWorker(const Object& receiver, |
| 3291 | const Function& callback, |
| 3292 | const char* resource_name); |
| 3293 | explicit AsyncProgressWorker(const Object& receiver, |
| 3294 | const Function& callback, |
| 3295 | const char* resource_name, |
| 3296 | const Object& resource); |
| 3297 | |
| 3298 | // Optional callback of Napi::ThreadSafeFunction only available after |
| 3299 | // NAPI_VERSION 4. Refs: https://github.com/nodejs/node/pull/27791 |
| 3300 | #if NAPI_VERSION > 4 |
| 3301 | explicit AsyncProgressWorker(Napi::Env env); |
| 3302 | explicit AsyncProgressWorker(Napi::Env env, const char* resource_name); |
| 3303 | explicit AsyncProgressWorker(Napi::Env env, |
| 3304 | const char* resource_name, |
| 3305 | const Object& resource); |
| 3306 | #endif |
| 3307 | virtual void Execute(const ExecutionProgress& progress) = 0; |
| 3308 | virtual void OnProgress(const T* data, size_t count) = 0; |
| 3309 | |
| 3310 | private: |
| 3311 | void Execute() override; |
| 3312 | void Signal(); |
| 3313 | void SendProgress_(const T* data, size_t count); |
| 3314 | |
| 3315 | std::mutex _mutex; |
| 3316 | T* _asyncdata; |
| 3317 | size_t _asyncsize; |
| 3318 | bool _signaled; |
| 3319 | }; |
| 3320 |
nothing calls this directly
no outgoing calls
no test coverage detected