Last active
February 5, 2019 05:27
-
-
Save NickNaso/daccdb6d8642863816ed2fccdaa3c244 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include<napi.h> | |
| #include <chrono> | |
| #include <thread> | |
| #include <iostream> | |
| Napi::Value CallEmit(const Napi::CallbackInfo& info) { | |
| Napi::Env env = info.Env(); | |
| Napi::Function emit = info[0].As<Napi::Function>(); | |
| emit.Call({Napi::String::New(env, "start")}); | |
| // Here some long running task and return piece of data exectuing some task | |
| for(int i = 0; i < 3; i++) { | |
| std::this_thread::sleep_for(std::chrono::seconds(3)); | |
| emit.Call({Napi::String::New(env, "data"), Napi::String::New(env, "data ...")}); | |
| } | |
| emit.Call({Napi::String::New(env, "end")}); | |
| return Napi::String::New(env, "OK"); | |
| } | |
| // Init | |
| Napi::Object Init(Napi::Env env, Napi::Object exports) { | |
| exports.Set(Napi::String::New(env, "callEmit"), Napi::Function::New(env, CallEmit)); | |
| return exports; | |
| } | |
| NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment