##// END OF EJS Templates
working on core/Cancellation
working on core/Cancellation

File last commit:

r17:b8fc13e5c702 propose cancellat...
r17:b8fc13e5c702 propose cancellat...
Show More
Cancellation.ts
66 lines | 1.4 KiB | video/mp2t | TypeScriptLexer
/ src / ts / Cancellation.ts
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 import { ICancellation } from "./interfaces";
cin
working on core/Cancellation
r17 import { argumentNotNull } from "./safe";
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13
export class Cancellation implements ICancellation {
cin
working on core/Cancellation
r17 private _reason: any;
private _cbs: Array<(e) => void>;
constructor(action: (cancel: (e) => void) => void) {
argumentNotNull(action, "action");
action(this._cancel.bind(this));
}
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 isSupported(): boolean {
cin
working on core/Cancellation
r17 return true;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
throwIfRequested(): void {
cin
working on core/Cancellation
r17 if (this._reason)
throw this._reason;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
cin
working on core/Cancellation
r17
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 isRequested(): boolean {
cin
working on core/Cancellation
r17 return !!this._reason;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
cin
working on core/Cancellation
r17 register(cb: (e: any) => void): void {
argumentNotNull(cb, "cb");
if (this._reason) {
cb(this._reason);
} else {
if (!this._cbs)
this._cbs = [cb];
else
this._cbs.push(cb);
}
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
cin
working on core/Cancellation
r17 private _cancel(reason) {
if (this._reason)
return;
this._reason = (reason = reason || new Error("Operation cancelled"));
if (this._cbs) {
this._cbs.forEach(cb => cb(reason));
this._cbs = null;
}
}
static readonly none: ICancellation = {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 isSupported(): boolean {
return false;
},
throwIfRequested(): void {
},
cin
working on core/Cancellation
r17
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 isRequested(): boolean {
return false;
},
cin
working on core/Cancellation
r17
register(_cb: (e: any) => void): void {
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
};
}