[MessageHandler] Convert the deleteStreamController helper function to a "private" method instead

This commit is contained in:
Jonas Jenwald 2019-10-06 13:52:25 +02:00
parent 0786363b7c
commit 9201c8dad4

View File

@ -334,20 +334,6 @@ MessageHandler.prototype = {
const streamId = data.streamId; const streamId = data.streamId;
const comObj = this.comObj; const comObj = this.comObj;
let deleteStreamController = () => {
// Delete the `streamController` only when the start, pull, and cancel
// capabilities have settled, to prevent `TypeError`s.
Promise.all([
this.streamControllers[streamId].startCall,
this.streamControllers[streamId].pullCall,
this.streamControllers[streamId].cancelCall
].map(function(capability) {
return capability && capability.promise.catch(function() { });
})).then(() => {
delete this.streamControllers[streamId];
});
};
switch (data.stream) { switch (data.stream) {
case StreamKind.START_COMPLETE: case StreamKind.START_COMPLETE:
if (data.success) { if (data.success) {
@ -423,14 +409,14 @@ MessageHandler.prototype = {
} }
this.streamControllers[streamId].isClosed = true; this.streamControllers[streamId].isClosed = true;
this.streamControllers[streamId].controller.close(); this.streamControllers[streamId].controller.close();
deleteStreamController(); this._deleteStreamController(streamId);
break; break;
case StreamKind.ERROR: case StreamKind.ERROR:
assert(this.streamControllers[streamId], assert(this.streamControllers[streamId],
'error should have stream controller'); 'error should have stream controller');
this.streamControllers[streamId].controller.error( this.streamControllers[streamId].controller.error(
wrapReason(data.reason)); wrapReason(data.reason));
deleteStreamController(); this._deleteStreamController(streamId);
break; break;
case StreamKind.CANCEL_COMPLETE: case StreamKind.CANCEL_COMPLETE:
if (data.success) { if (data.success) {
@ -439,7 +425,7 @@ MessageHandler.prototype = {
this.streamControllers[streamId].cancelCall.reject( this.streamControllers[streamId].cancelCall.reject(
wrapReason(data.reason)); wrapReason(data.reason));
} }
deleteStreamController(); this._deleteStreamController(streamId);
break; break;
case StreamKind.CANCEL: case StreamKind.CANCEL:
if (!this.streamSinks[streamId]) { if (!this.streamSinks[streamId]) {
@ -475,6 +461,19 @@ MessageHandler.prototype = {
} }
}, },
async _deleteStreamController(streamId) {
// Delete the `streamController` only when the start, pull, and cancel
// capabilities have settled, to prevent `TypeError`s.
await Promise.all([
this.streamControllers[streamId].startCall,
this.streamControllers[streamId].pullCall,
this.streamControllers[streamId].cancelCall
].map(function(capability) {
return capability && capability.promise.catch(function() { });
}));
delete this.streamControllers[streamId];
},
/** /**
* Sends raw message to the comObj. * Sends raw message to the comObj.
* @private * @private