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

Class ProgressQueueWorker

test/cpp/asyncprogressqueueworkerstream.cpp:21–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20template<typename T>
21class ProgressQueueWorker : public AsyncProgressQueueWorker<T> {
22 public:
23 ProgressQueueWorker(
24 Callback *callback
25 , Callback *progress
26 , int iters)
27 : AsyncProgressQueueWorker<T>(callback), progress(progress)
28 , iters(iters) {}
29
30 ~ProgressQueueWorker() {
31 delete progress;
32 }
33
34 void Execute (
35 const typename AsyncProgressQueueWorker<T>::ExecutionProgress& progress) {
36 data_t data;
37 for (int i = 0; i < iters; ++i) {
38 data.index = i;
39 data.data = i * 2;
40 progress.Send(&data, 1);
41 }
42 }
43
44 void HandleProgressCallback(const T *data, size_t count) {
45 HandleScope scope;
46 v8::Local<v8::Object> obj = Nan::New<v8::Object>();
47 Nan::Set(
48 obj,
49 Nan::New("index").ToLocalChecked(),
50 New<v8::Integer>(data->index));
51 Nan::Set(
52 obj,
53 Nan::New("data").ToLocalChecked(),
54 New<v8::Integer>(data->data));
55
56 v8::Local<v8::Value> argv[] = { obj };
57 progress->Call(1, argv, this->async_resource);
58 }
59
60 private:
61 Callback *progress;
62 int iters;
63};
64
65NAN_METHOD(DoProgress) {
66 Callback *progress = new Callback(To<v8::Function>(info[1]).ToLocalChecked());

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected