Closes all promises/streams when handler is destroyed.

This commit is contained in:
Yury Delendik 2017-09-28 16:45:04 -05:00
parent 25806d17f4
commit 71b0e4e818
3 changed files with 41 additions and 15 deletions

View file

@ -1632,8 +1632,33 @@ MessageHandler.prototype = {
}
},
destroy() {
close(reason) {
this.comObj.removeEventListener('message', this._onComObjOnMessage);
// Reject all promises and streams.
for (let i in this.callbacksCapabilities) {
const callbackCapability = this.callbacksCapabilities[i];
callbackCapability.reject(reason);
}
for (let i in this.streamSinks) {
const sink = this.streamSinks[i];
sink.sinkCapability.reject(reason);
}
for (let i in this.streamControllers) {
const controller = this.streamControllers[i];
if (!controller.isClosed) {
controller.controller.error(reason);
}
if (controller.startCall) {
controller.startCall.reject(reason);
}
if (controller.pullCall) {
controller.pullCall.reject(reason);
}
if (controller.cancelCall) {
controller.cancelCall.reject(reason);
}
}
},
};