##// END OF EJS Templates
Merged in propose observables (pull request #2)...
Merged in propose observables (pull request #2) Propose observables

File last commit:

r22:93dca6f27f52 propose observables
r29:e0b5fc764f84 merge default
Show More
AsyncComponent.ts
39 lines | 1.2 KiB | video/mp2t | TypeScriptLexer
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 import { Cancellation } from "../Cancellation";
cin
Code cleanup,...
r22 import { IAsyncComponent, ICancellation, ICancellable, IDestroyable } from "../interfaces";
import { destroy } from "../safe";
cin
Async operation cancellation proposal...
r9
cin
Code cleanup,...
r22 export class AsyncComponent implements IAsyncComponent, ICancellable {
_cancel: (e) => void;
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 _completion: Promise<void> = Promise.resolve();
cin
Async operation cancellation proposal...
r9
getCompletion() { return this._completion };
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 runOperation(op: (ct: ICancellation) => any, ct: ICancellation = Cancellation.none) {
cin
Code cleanup,...
r22 // create inner cancellation bound to the passed cancellation token
let h: IDestroyable;
let inner = new Cancellation(cancel => {
this._cancel = cancel;
h = ct.register(cancel);
});
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 // TODO create cancellation source here
cin
Code cleanup,...
r22 let guard = async () => {
try {
await op(inner);
} finally {
// after the operation is complete we need to cleanup the
// resources
destroy(h);
this._cancel = null;
}
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 }
cin
Async operation cancellation proposal...
r9
cin
refactoring, all common interfaces placed to core/interfaces.ts...
r13 return this._completion = guard();
cin
Async operation cancellation proposal...
r9 }
cin
Code cleanup,...
r22
cancel(reason) {
if (this._cancel)
this._cancel(reason);
}
cin
Async operation cancellation proposal...
r9 }