##// END OF EJS Templates
spelling fixes
spelling fixes

File last commit:

r18:a8dda6a00a16 propose cancellat...
r19:9d394c2adc2b propose cancellat...
Show More
Cancellation.ts
88 lines | 1.8 KiB | video/mp2t | TypeScriptLexer
/ src / ts / Cancellation.ts
cin
added CancellationTests...
r18 import { ICancellation, IDestroyable } from "./interfaces";
cin
working on core/Cancellation
r17 import { argumentNotNull } from "./safe";
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13
cin
added CancellationTests...
r18 const destroyed = {
destroy() {
}
};
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
added CancellationTests...
r18 register(cb: (e: any) => void): IDestroyable {
cin
working on core/Cancellation
r17 argumentNotNull(cb, "cb");
if (this._reason) {
cb(this._reason);
cin
added CancellationTests...
r18 return destroyed;
cin
working on core/Cancellation
r17 } else {
if (!this._cbs)
this._cbs = [cb];
else
this._cbs.push(cb);
cin
added CancellationTests...
r18
let me = this;
return {
destroy() {
me._unregister(cb);
}
};
cin
working on core/Cancellation
r17 }
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
cin
added CancellationTests...
r18
private _unregister(cb) {
if(this._cbs) {
let i = this._cbs.indexOf(cb);
if ( i>=0 )
this._cbs.splice(i,1);
}
}
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
cin
added CancellationTests...
r18 register(_cb: (e: any) => void): IDestroyable {
return destroyed;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
};
}