-
-
Save anonymous/60cdc8562c3c6466046b12f8544ad0d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* wrapper.cpp */ | |
void SetProcessEmitter(const FunctionCallbackInfo<Value> &args) | |
{ | |
Nan::Callback *callback = new Nan::Callback(args[0].As<Function>()); | |
setProcessEmit(callback); | |
} | |
/* handlers.cpp */ | |
void asyncmsg(uv_async_t *handle) | |
{ | |
Nan::HandleScope scope; | |
v8::Isolate *isolate = v8::Isolate::GetCurrent(); | |
Local<Value> args[] = { | |
String::NewFromUtf8(isolate, "test"), | |
String::NewFromUtf8(isolate, readableData), | |
}; | |
cb->Call(2, args); | |
} | |
void setProcessEmit(Nan::Callback *callback) | |
{ | |
cb = callback; | |
loop = uv_default_loop(); | |
uv_async_init(loop, &async, asyncmsg); | |
} | |
/* init.js */ | |
// Load addon | |
const t = require('./build/Release/addon'); | |
// Connect to the scanner | |
t.start(); | |
// Logging function | |
var f = function f(i) { console.log(i); }; | |
// Display everything caught from this event | |
process.on("test", f); | |
// Send function to use -> Call first function in this gist | |
t.setProcessEmitter(process.emit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment