##// END OF EJS Templates
wip migrating on new typescript build plugin
wip migrating on new typescript build plugin

File last commit:

r172:3969a8fb8049 release v1.4.6 default
r174:b00d3153045c default
Show More
CancellationAggregate.ts
41 lines | 1.0 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / CancellationAggregate.ts
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
};
}
}