| 22 | // Unlike test/cpp/ayncprogressworker.cpp this test is explicitly templated. |
| 23 | template<typename T> |
| 24 | class ProgressWorker : public AsyncProgressWorkerBase<T> { |
| 25 | public: |
| 26 | ProgressWorker( |
| 27 | Callback *callback |
| 28 | , Callback *progress |
| 29 | , int milliseconds |
| 30 | , int iters) |
| 31 | : AsyncProgressWorkerBase<T>(callback), progress(progress) |
| 32 | , milliseconds(milliseconds), iters(iters) {} |
| 33 | |
| 34 | ~ProgressWorker() { |
| 35 | delete progress; |
| 36 | } |
| 37 | |
| 38 | void Execute ( |
| 39 | const typename AsyncProgressWorkerBase<T>::ExecutionProgress& progress) { |
| 40 | data_t data; |
| 41 | for (int i = 0; i < iters; ++i) { |
| 42 | data.index = i; |
| 43 | data.data = i * 2; |
| 44 | progress.Send(&data, 1); |
| 45 | Sleep(milliseconds); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void HandleProgressCallback(const T *data, size_t count) { |
| 50 | HandleScope scope; |
| 51 | v8::Local<v8::Object> obj = Nan::New<v8::Object>(); |
| 52 | Nan::Set( |
| 53 | obj, |
| 54 | Nan::New("index").ToLocalChecked(), |
| 55 | New<v8::Integer>(data->index)); |
| 56 | Nan::Set( |
| 57 | obj, |
| 58 | Nan::New("data").ToLocalChecked(), |
| 59 | New<v8::Integer>(data->data)); |
| 60 | |
| 61 | v8::Local<v8::Value> argv[] = { obj }; |
| 62 | progress->Call(1, argv, this->async_resource); |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | Callback *progress; |
| 67 | int milliseconds; |
| 68 | int iters; |
| 69 | }; |
| 70 | |
| 71 | NAN_METHOD(DoProgress) { |
| 72 | Callback *progress = new Callback(To<v8::Function>(info[2]).ToLocalChecked()); |
nothing calls this directly
no outgoing calls
no test coverage detected