0

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);
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I did as you said, but did not work. That is, result now Persistent, array is Local <Array>. error C2679: binary '=' : no operator found which takes a right-hand operand of type 'v8::Handle<T>' (or there is no acceptable conversion)
Another feature. I do not understand why she proshodit. If you declare a function wmiWorker Local <Array> array = Array :: New (1), all compiled, the cout << "str"; in this function is not called. If you take away - all works. What's the problem?
@YaroslavL. Woops, fixed. For your second question, can you post an example in your question? I don't 100% follow what you are asking.
Local <Array> ABC = Array::New(1); If ABC announced in wmiWorker (that is, if I announced it there), then the test case does not output anything (but compiles and does not throw an error), if you remove from there ABC, print all you need (aaaETO A BLA undefined ETO B BLA ['ccc']) pastie.org/8028942
@YaroslavL. I updated my answer with what I believe your issue to be.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.