From 17116917f74cb1317b70a023eaa9b652cdba2a5d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 13 Jul 2019 13:08:29 +0200 Subject: [PATCH] Remove useless `wrapReason` calls in the `MessageHandler` class Currently `wrapReason` is manually called at *every* `resolveOrReject` call-site, despite it being completely unnecessary unless there's an actual error being handled. This is obviously inefficient, and it's easy enough to avoid by having `resolveOrReject` handle this only when actually needed. --- src/shared/message_handler.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/shared/message_handler.js b/src/shared/message_handler.js index cd2398635..a8501dc6a 100644 --- a/src/shared/message_handler.js +++ b/src/shared/message_handler.js @@ -52,11 +52,11 @@ function makeReasonSerializable(reason) { return new UnknownErrorException(reason.message, reason.toString()); } -function resolveOrReject(capability, success, reason) { - if (success) { +function resolveOrReject(capability, data) { + if (data.success) { capability.resolve(); } else { - capability.reject(reason); + capability.reject(wrapReason(data.reason)); } } @@ -341,12 +341,10 @@ MessageHandler.prototype = { switch (data.stream) { case 'start_complete': - resolveOrReject(this.streamControllers[data.streamId].startCall, - data.success, wrapReason(data.reason)); + resolveOrReject(this.streamControllers[data.streamId].startCall, data); break; case 'pull_complete': - resolveOrReject(this.streamControllers[data.streamId].pullCall, - data.success, wrapReason(data.reason)); + resolveOrReject(this.streamControllers[data.streamId].pullCall, data); break; case 'pull': // Ignore any pull after close is called. @@ -395,8 +393,7 @@ MessageHandler.prototype = { deleteStreamController(); break; case 'cancel_complete': - resolveOrReject(this.streamControllers[data.streamId].cancelCall, - data.success, wrapReason(data.reason)); + resolveOrReject(this.streamControllers[data.streamId].cancelCall, data); deleteStreamController(); break; case 'cancel':