nodejs/nan

Assigning Callbacks Within Callbacks

smalls12 opened this issue · 0 comments

Hi,

I have a C++ library with an API call which will take in a callback.
That callback will return a reference to another callback that is to be set while in the first callback.
I'm trying to find a way to do this.

Assigning the first callback is straightforward from js to c++

Nan::MaybeLocal<v8::Function> function_ = Nan::To<v8::Function>(info[0]);
Nan::Callback* callback_ = new Nan::Callback(function_.ToLocalChecked());

and then calling the callback

Nan::HandleScope scope;
Nan::AsyncResource resource("async_connect::on_connect");

v8::Local<v8::Object> target = Nan::New<v8::Object>();

resource.runInAsyncScope(target, callback_->GetFunction(), 0, nullptr);

this all works fine ( no arguments provided with the callback ).

So I am trying to figure out how I can provide an argument to that callback, from c++ into js, that would allow storing another callback.