| 3210 | }; |
| 3211 | template <typename DataType> |
| 3212 | class AsyncProgressWorkerBase : public AsyncWorker { |
| 3213 | public: |
| 3214 | virtual void OnWorkProgress(DataType* data) = 0; |
| 3215 | class ThreadSafeData { |
| 3216 | public: |
| 3217 | ThreadSafeData(AsyncProgressWorkerBase* asyncprogressworker, DataType* data) |
| 3218 | : _asyncprogressworker(asyncprogressworker), _data(data) {} |
| 3219 | |
| 3220 | AsyncProgressWorkerBase* asyncprogressworker() { |
| 3221 | return _asyncprogressworker; |
| 3222 | } |
| 3223 | DataType* data() { return _data; } |
| 3224 | |
| 3225 | private: |
| 3226 | AsyncProgressWorkerBase* _asyncprogressworker; |
| 3227 | DataType* _data; |
| 3228 | }; |
| 3229 | void OnWorkComplete(Napi::Env env, napi_status status) override; |
| 3230 | |
| 3231 | protected: |
| 3232 | explicit AsyncProgressWorkerBase(const Object& receiver, |
| 3233 | const Function& callback, |
| 3234 | const char* resource_name, |
| 3235 | const Object& resource, |
| 3236 | size_t queue_size = 1); |
| 3237 | virtual ~AsyncProgressWorkerBase(); |
| 3238 | |
| 3239 | // Optional callback of Napi::ThreadSafeFunction only available after |
| 3240 | // NAPI_VERSION 4. Refs: https://github.com/nodejs/node/pull/27791 |
| 3241 | #if NAPI_VERSION > 4 |
| 3242 | explicit AsyncProgressWorkerBase(Napi::Env env, |
| 3243 | const char* resource_name, |
| 3244 | const Object& resource, |
| 3245 | size_t queue_size = 1); |
| 3246 | #endif |
| 3247 | |
| 3248 | static inline void OnAsyncWorkProgress(Napi::Env env, |
| 3249 | Napi::Function jsCallback, |
| 3250 | void* data); |
| 3251 | |
| 3252 | napi_status NonBlockingCall(DataType* data); |
| 3253 | |
| 3254 | private: |
| 3255 | ThreadSafeFunction _tsfn; |
| 3256 | bool _work_completed = false; |
| 3257 | napi_status _complete_status; |
| 3258 | static inline void OnThreadSafeFunctionFinalize( |
| 3259 | Napi::Env env, void* data, AsyncProgressWorkerBase* context); |
| 3260 | }; |
| 3261 | |
| 3262 | template <class T> |
| 3263 | class AsyncProgressWorker : public AsyncProgressWorkerBase<void> { |
nothing calls this directly
no outgoing calls
no test coverage detected