AsyncComponent.ts
16 lines
| 531 B
| video/mp2t
|
TypeScriptLexer
|
|
r13 | import { Cancellation } from "../Cancellation"; | |
| import { IAsyncComponent, ICancellation } from "../interfaces"; | |||
|
|
r9 | ||
|
|
r13 | export class AsyncComponent implements IAsyncComponent { | |
| _completion: Promise<void> = Promise.resolve(); | |||
|
|
r9 | ||
| getCompletion() { return this._completion }; | |||
|
|
r13 | runOperation(op: (ct: ICancellation) => any, ct: ICancellation = Cancellation.none) { | |
| // TODO create cancellation source here | |||
| async function guard() { | |||
| await op(ct); | |||
| } | |||
|
|
r9 | ||
|
|
r13 | return this._completion = guard(); | |
|
|
r9 | } | |
| } |
