diff options
Diffstat (limited to 'src/node/ext/completion_queue_async_worker.cc')
-rw-r--r-- | src/node/ext/completion_queue_async_worker.cc | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/node/ext/completion_queue_async_worker.cc b/src/node/ext/completion_queue_async_worker.cc index 8de7db66d5..a1f390f64b 100644 --- a/src/node/ext/completion_queue_async_worker.cc +++ b/src/node/ext/completion_queue_async_worker.cc @@ -35,10 +35,10 @@ #include <nan.h> #include "grpc/grpc.h" +#include "grpc/support/log.h" #include "grpc/support/time.h" #include "completion_queue_async_worker.h" -#include "event.h" -#include "tag.h" +#include "call.h" namespace grpc { namespace node { @@ -58,6 +58,9 @@ CompletionQueueAsyncWorker::~CompletionQueueAsyncWorker() {} void CompletionQueueAsyncWorker::Execute() { result = grpc_completion_queue_next(queue, gpr_inf_future); + if (result->data.op_complete != GRPC_OP_OK) { + SetErrorMessage("The batch encountered an error"); + } } grpc_completion_queue *CompletionQueueAsyncWorker::GetQueue() { return queue; } @@ -75,14 +78,26 @@ void CompletionQueueAsyncWorker::Init(Handle<Object> exports) { void CompletionQueueAsyncWorker::HandleOKCallback() { NanScope(); - NanCallback event_callback(GetTagHandle(result->tag).As<Function>()); - Handle<Value> argv[] = {CreateEventObject(result)}; + NanCallback *callback = GetTagCallback(result->tag); + Handle<Value> argv[] = {NanNull(), GetTagNodeValue(result->tag)}; + + callback->Call(2, argv); DestroyTag(result->tag); grpc_event_finish(result); result = NULL; +} + +void CompletionQueueAsyncWorker::HandleErrorCallback() { + NanScope(); + NanCallback *callback = GetTagCallback(result->tag); + Handle<Value> argv[] = {NanError(ErrorMessage())}; - event_callback.Call(1, argv); + callback->Call(1, argv); + + DestroyTag(result->tag); + grpc_event_finish(result); + result = NULL; } } // namespace node |