Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning Callbacks Within Callbacks #908

Open
smalls12 opened this issue Feb 14, 2021 · 0 comments
Open

Assigning Callbacks Within Callbacks #908

smalls12 opened this issue Feb 14, 2021 · 0 comments

Comments

@smalls12
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant