I am writing asynchronous module, but I can not pass an array structure. Please help. That's the error appears. How to avoid it? error C2440: '=' : cannot convert from 'v8::Handle' to 'v8::Array *'
struct Async {
Handle<v8::Array> result;
}
void wmiWorker(uv_work_t* req) {
Async* request = (Async*)req->data;
*(request->result) = getArray(1);
}
Handle<Array> getArray(int x) {
HandleScope handle_scope;
Handle<Array> array = Array::New(3);
if (array.IsEmpty())
return Handle<Array>();
array->Set(0, Integer::New(x));
return handle_scope.Close(array);
}
Your line
*(request->result) = getArray(1);
assigns a Handle<Array> to *(Handle<Array>) (which means Array*), which is not valid.
However even with that, there is an important factor that you are not taking into account. Your wmiWorker function is running in a separate thread. NodeJS and V8 only allow a single thread of execution for JS, and what you are attempting to do is create a JS array inside of a separate thread.
Instead you will need to create a vector or something, and generate the V8 array from that inside of the work callback's after_work callback.