MCPcopy Create free account
hub / github.com/nodejs/nan / AsyncProgressQueueWorker

Class AsyncProgressQueueWorker

nan.h:2310–2379  ·  view source on GitHub ↗

abstract */

Source from the content-addressed store, hash-verified

2308template<class T>
2309/* abstract */
2310class AsyncProgressQueueWorker : public AsyncBareProgressQueueWorker<T> {
2311 public:
2312 explicit AsyncProgressQueueWorker(
2313 Callback *callback_,
2314 const char* resource_name = "nan:AsyncProgressQueueWorker")
2315 : AsyncBareProgressQueueWorker<T>(callback_) {
2316 uv_mutex_init(&async_lock);
2317 }
2318
2319 virtual ~AsyncProgressQueueWorker() {
2320 uv_mutex_lock(&async_lock);
2321
2322 while (!asyncdata_.empty()) {
2323 std::pair<T*, size_t> &datapair = asyncdata_.front();
2324 T *data = datapair.first;
2325
2326 asyncdata_.pop();
2327
2328 delete[] data;
2329 }
2330
2331 uv_mutex_unlock(&async_lock);
2332 uv_mutex_destroy(&async_lock);
2333 }
2334
2335 void WorkComplete() {
2336 WorkProgress();
2337 AsyncWorker::WorkComplete();
2338 }
2339
2340 void WorkProgress() {
2341 uv_mutex_lock(&async_lock);
2342
2343 while (!asyncdata_.empty()) {
2344 std::pair<T*, size_t> &datapair = asyncdata_.front();
2345
2346 T *data = datapair.first;
2347 size_t size = datapair.second;
2348
2349 asyncdata_.pop();
2350 uv_mutex_unlock(&async_lock);
2351
2352 // Don't send progress events after we've already completed.
2353 if (this->callback) {
2354 this->HandleProgressCallback(data, size);
2355 }
2356
2357 delete[] data;
2358
2359 uv_mutex_lock(&async_lock);
2360 }
2361
2362 uv_mutex_unlock(&async_lock);
2363 }
2364
2365 private:
2366 void SendProgress_(const T *data, size_t count) {
2367 T *new_data = new T[count];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected