mirror of https://github.com/grpc/grpc-node.git
Added an inline C++ function to replace a deprecated nan function
This commit is contained in:
parent
2cbaf1e9ac
commit
0f7084ff7a
|
@ -619,7 +619,7 @@ NAN_METHOD(Call::StartBatch) {
|
|||
call->wrapped_call, &ops[0], nops, new struct tag(
|
||||
callback, op_vector.release(), resources), NULL);
|
||||
if (error != GRPC_CALL_OK) {
|
||||
return NanThrowError("startBatch failed", error);
|
||||
return NanThrowError(nanErrorWithCode("startBatch failed", error));
|
||||
}
|
||||
CompletionQueueAsyncWorker::Next();
|
||||
NanReturnUndefined();
|
||||
|
@ -633,7 +633,7 @@ NAN_METHOD(Call::Cancel) {
|
|||
Call *call = ObjectWrap::Unwrap<Call>(args.This());
|
||||
grpc_call_error error = grpc_call_cancel(call->wrapped_call, NULL);
|
||||
if (error != GRPC_CALL_OK) {
|
||||
return NanThrowError("cancel failed", error);
|
||||
return NanThrowError(nanErrorWithCode("cancel failed", error));
|
||||
}
|
||||
NanReturnUndefined();
|
||||
}
|
||||
|
|
13
ext/call.h
13
ext/call.h
|
@ -51,6 +51,19 @@ namespace node {
|
|||
using std::unique_ptr;
|
||||
using std::shared_ptr;
|
||||
|
||||
/**
|
||||
* Helper function for throwing errors with a grpc_call_error value.
|
||||
* Modified from the answer by Gus Goose to
|
||||
* http://stackoverflow.com/questions/31794200.
|
||||
*/
|
||||
inline v8::Local<v8::Value> nanErrorWithCode(const char *msg,
|
||||
grpc_call_error code) {
|
||||
NanEscapableScope();
|
||||
v8::Local<v8::Object> err = NanError(msg).As<v8::Object>();
|
||||
err->Set(NanNew("code"), NanNew<v8::Uint32>(code));
|
||||
return NanEscapeScope(err);
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> ParseMetadata(const grpc_metadata_array *metadata_array);
|
||||
|
||||
class PersistentHolder {
|
||||
|
|
|
@ -235,7 +235,7 @@ NAN_METHOD(Server::RequestCall) {
|
|||
new struct tag(new NanCallback(args[0].As<Function>()), ops.release(),
|
||||
shared_ptr<Resources>(nullptr)));
|
||||
if (error != GRPC_CALL_OK) {
|
||||
return NanThrowError("requestCall failed", error);
|
||||
return NanThrowError(nanErrorWithCode("requestCall failed", error));
|
||||
}
|
||||
CompletionQueueAsyncWorker::Next();
|
||||
NanReturnUndefined();
|
||||
|
|
Loading…
Reference in New Issue