mapbox / node-cpp-skel

Skeleton for bindings to C++ libraries for Node.js using node-addon-api
Creative Commons Zero v1.0 Universal
72 stars 10 forks source link

Proper handling of callbacks with Nan #5

Closed mapsam closed 7 years ago

mapsam commented 8 years ago

Diving into #4 led me to checking our usage of Nan::MakeCallback, which led me to a few more tickets out in the wild about how it might not be the best thing in the world. Can we improve on our current usage?

refs:

cc @springmeyer @camilleanne @GretaCB

GretaCB commented 8 years ago

How can we consistify?

springmeyer commented 7 years ago

I re-read the original post linked above (https://github.com/nodejs/nan/issues/284) and my conclusion is that we don't need to make any changes. The issue raised at https://github.com/nodejs/nan/issues/284 is solvable by new APIs in nan to call callbacks directly, but does not apply to our usecase. The post says:

This form (MakeCallback) is intended only for use by C++ code that was dispatched from the libuv event loop, and not for C++ code that was invoked from JS code.

In the case of node-cpp-skel we are only doing the former: calling a callback after returning from the libuv event loop.