##// END OF EJS Templates
Added tag v1.4.5 for changeset 1391543e8282
Added tag v1.4.5 for changeset 1391543e8282

File last commit:

r170:1391543e8282 v1.4.5 default
r171:2ad4aeec02ff default
Show More
CancellationAggregate.ts
41 lines | 1.0 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / CancellationAggregate.ts
cin
Added Cancellation.combine(...tokens) method to combine multiple cancellation...
r170 import { ICancellation, IDestroyable } from "./interfaces";
export class CancellationAggregate implements ICancellation {
private readonly _tokens: ICancellation[];
constructor(tokens: ICancellation[]) {
this._tokens = tokens || [];
}
throwIfRequested() {
this._tokens.forEach(ct => ct.throwIfRequested());
}
isRequested() {
return this._tokens.some(ct => ct.isRequested());
}
isSupported() {
return !!this._tokens.length;
}
register(cb: (e: any) => void): IDestroyable {
let fired = false;
const once = (e: any) => {
if (!fired) {
fired = true;
destroy();
cb(e);
}
}
const destroy = () => subscriptions
.splice(0,subscriptions.length) // empty array
.forEach(subscription => subscription.destroy()); // cleanup
const subscriptions = this._tokens.map(ct => ct.register(once))
return {
destroy
};
}
}