Created
March 7, 2017 10:20
-
-
Save jupp0r/5f11c0ee2b046b0ab89660ce85ea480e to your computer and use it in GitHub Desktop.
C++ function returning an ES6 promise
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
#include <node.h> | |
#include "Test.h" | |
namespace demo { | |
using v8::FunctionCallbackInfo; | |
using v8::Isolate; | |
using v8::Local; | |
using v8::Object; | |
using v8::String; | |
using v8::Value; | |
void Method(const FunctionCallbackInfo<Value> &args) { | |
Isolate *isolate = args.GetIsolate(); | |
auto resolver = v8::Promise::Resolver::New(isolate); | |
args.GetReturnValue().Set(resolver->GetPromise()); | |
resolver->Resolve(String::NewFromUtf8(isolate, "world")); | |
} | |
void init(Local<Object> exports) { NODE_SET_METHOD(exports, "hello", Method); } | |
NODE_MODULE(addon, init) | |
} // namespace demo |
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
let addon = require('./build/Release/webidl-poc.node') | |
addon.hello().then(msg => console.log(msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment