##// END OF EJS Templates
Merge with ts-plugin
Merge with ts-plugin

File last commit:

r59:ba3ff79c2832 default
r102:32db28d9ca07 merge v1.3.2 default
Show More
AsyncComponent.ts
40 lines | 1.2 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / components / AsyncComponent.ts
cin
changed the project structure
r49 import { Cancellation } from "../Cancellation";
import { IAsyncComponent, ICancellation, ICancellable, IDestroyable } from "../interfaces";
import { destroy } from "../safe";
export class AsyncComponent implements IAsyncComponent, ICancellable {
cin
working on support commonjs modules format
r59 _cancel: (e: any) => void;
cin
changed the project structure
r49
_completion: Promise<void> = Promise.resolve();
cin
text/format refactoring
r54 getCompletion() { return this._completion; }
cin
changed the project structure
r49
runOperation(op: (ct: ICancellation) => any, ct: ICancellation = Cancellation.none) {
// create inner cancellation bound to the passed cancellation token
let h: IDestroyable;
cin
text/format refactoring
r54 const inner = new Cancellation(cancel => {
cin
changed the project structure
r49
this._cancel = cancel;
h = ct.register(cancel);
});
// TODO create cancellation source here
cin
text/format refactoring
r54 const guard = async () => {
cin
changed the project structure
r49 try {
await op(inner);
} finally {
// after the operation is complete we need to cleanup the
// resources
destroy(h);
this._cancel = null;
}
cin
text/format refactoring
r54 };
cin
changed the project structure
r49
return this._completion = guard();
}
cin
working on support commonjs modules format
r59 cancel(reason: any) {
cin
changed the project structure
r49 if (this._cancel)
this._cancel(reason);
}
cin
text/format refactoring
r54 }