How to call a callback with libuv in Node.js V12

426 views
Skip to first unread message

Jake Le

unread,
Feb 16, 2015, 8:44:41 PM2/16/15
to nod...@googlegroups.com

In Node.js v0.10.xx, calling a callback requires a Persistent<Function>.    Does anyone know to make the below code work in Node.js V12?

struct Baton {
      uv_work_t request;
      Persistent<Function> callback;
};

somefunction() {
...
Baton *baton = new Baton();
baton->request.data = baton;
baton->callback = Persistent<Function>::New(Handle<Function>::Cast(args[0]));

uv_queue_work(uv_default_loop(), &baton->request, Work, AfterWork);..
}

void AfterWork(uv_work_t *req) {
 Baton *baton = static_cast<Baton *>(req->data); HandleScope scope;

const int argc = 1;
Handle<Value> argv[argc] = { String::NewFromUtf8(isolate, "hello world") };

TryCatch try_catch;
  baton->callback->Call(Context::GetCurrent()->Global(), argc, argv);
if (try_catch.HasCaught()) { node::FatalException(try_catch); }
      baton->callback.Dispose();
      baton->callback.Clear();
..
}

Thanks,
-Jake

Christian Taltas

unread,
Feb 17, 2015, 2:54:32 PM2/17/15
to nod...@googlegroups.com
Hi Jake

It is worth reading strongloop blog:


Regards



--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/03c2fc5d-86c5-4b00-b732-8841de2ea574%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Christian Taltas
KPMG Technologies Services - Directeur Général



Jake Le

unread,
Feb 17, 2015, 7:08:38 PM2/17/15
to nod...@googlegroups.com

Christian,

Thank you very much.  It was  the Persistent<Function> conversion that I needed.  Great blog!!! :)

-Jake
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/03c2fc5d-86c5-4b00-b732-8841de2ea574%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages