00/src/emit-from-cpp.cc
// All work but it's not a good practice bacause all long running task should be
// executed out of the event loop
All work but it's not a good practice bacause all long running task should be
executed out of the event loop
All work but it ' s not a good practice bacause all long running task should be executed out of the event loop
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")});
    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");
}
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 , " " ) } ) ; for ( int i = 0 ; i < 3 ; i ++ ) { std :: this_thread :: sleep_for ( std :: chrono :: seconds ( 3 ) ) ; emit . Call ( { Napi :: String :: New ( env , " " ) , Napi :: String :: New ( env , " " ) } ) ; } emit . Call ( { Napi :: String :: New ( env , " " ) } ) ; return Napi :: String :: New ( env , " " ) ; }
All work but it's not a good practice bacause all long running task should be
executed out of the event loop
All work but it ' s not a good practice bacause all long running task should be executed out of the event loop
// Here some long running task and return piece of data exectuing some task