diff options
author | murgatroid99 <mlumish@google.com> | 2017-04-06 13:54:37 -0700 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2017-04-06 13:54:37 -0700 |
commit | 2a4ea2daafaf9a79f749d1fef1a6a5970613b9fb (patch) | |
tree | 6a5edd771e05e23ef70cb7fe3f3e75d9b6a019f6 /src | |
parent | 130568e5151ed468d8b40362272104c10aa6488e (diff) |
Node: consolidate call destruction logic
Diffstat (limited to 'src')
-rw-r--r-- | src/node/ext/call.cc | 18 | ||||
-rw-r--r-- | src/node/ext/call.h | 2 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 62f0130d53..769f744b86 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -515,16 +515,20 @@ void DestroyTag(void *tag) { delete tag_struct; } +void Call::DestroyCall() { + if (this->wrapped_call != NULL) { + grpc_call_destroy(this->wrapped_call); + this->wrapped_call = NULL; + } +} + Call::Call(grpc_call *call) : wrapped_call(call), pending_batches(0), has_final_op_completed(false) { } Call::~Call() { - if (wrapped_call != NULL) { - grpc_call_destroy(wrapped_call); - wrapped_call = NULL; - } + DestroyCall(); } void Call::Init(Local<Object> exports) { @@ -570,10 +574,8 @@ void Call::CompleteBatch(bool is_final_op) { this->has_final_op_completed = true; } this->pending_batches--; - if (this->has_final_op_completed && this->pending_batches == 0 && - this->wrapped_call != NULL) { - grpc_call_destroy(this->wrapped_call); - this->wrapped_call = NULL; + if (this->has_final_op_completed && this->pending_batches == 0) { + this->DestroyCall(); } } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index cceec9c45b..7fd03ca1de 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -76,6 +76,8 @@ class Call : public Nan::ObjectWrap { Call(const Call &); Call &operator=(const Call &); + void DestroyCall(); + static NAN_METHOD(New); static NAN_METHOD(StartBatch); static NAN_METHOD(Cancel); |