From b548bafef74293cb033b6975f9236bc3db449a02 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 13 Jul 2019 17:47:39 +0200 Subject: [PATCH] Simplify, and inline, the `finalize` function in the `MessageHandler` class The `finalize` helper function has only a *single* call-site, and furthermore it's just a one-liner too. Furthermore it's only ever called with a `Promise` as its argument, meaning that it's unnecessarily convoluted as well (i.e. the `Promise.resolve()` part shouldn't be necessary). Hence this code can be both simplified *and* inlined at its only call-site instead. --- src/shared/message_handler.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/shared/message_handler.js b/src/shared/message_handler.js index a8501dc6a..29e16b718 100644 --- a/src/shared/message_handler.js +++ b/src/shared/message_handler.js @@ -60,10 +60,6 @@ function resolveOrReject(capability, data) { } } -function finalize(promise) { - return Promise.resolve(promise).catch(() => {}); -} - function MessageHandler(sourceName, targetName, comObj) { this.sourceName = sourceName; this.targetName = targetName; @@ -326,14 +322,14 @@ MessageHandler.prototype = { }; let deleteStreamController = () => { - // Delete streamController only when start, pull and - // cancel callbacks are resolved, to avoid "TypeError". + // Delete the `streamController` only when the start, pull, and cancel + // capabilities have settled, to prevent `TypeError`s. Promise.all([ this.streamControllers[data.streamId].startCall, this.streamControllers[data.streamId].pullCall, this.streamControllers[data.streamId].cancelCall ].map(function(capability) { - return capability && finalize(capability.promise); + return capability && capability.promise.catch(function() { }); })).then(() => { delete this.streamControllers[data.streamId]; });