-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR gives users greater flexibility with Excalibur Coroutines! * Optionally ask coroutines not to start immediately ```typescript ex.coroutine(function* () { .. }, { autostart: false }); ``` * New `CoroutineInstance` is returned that is also awaitable ```typescript export interface CoroutineOptions { timing?: ScheduledCallbackTiming; autostart?: boolean; } export interface CoroutineInstance extends PromiseLike<void> { isRunning(): boolean; isComplete(): boolean; done: Promise<void>; generator: Generator<CoroutineInstance | number | Promise<any> | undefined, void, number>; start: () => CoroutineInstance; cancel: () => void; then: Thenable; [Symbol.iterator]: () => Generator<CoroutineInstance | number | Promise<any> | undefined, void, number>; } ``` ```typescript const co = ex.coroutine(function* () { yield 100; }); await co; // wait for coroutine to finish ``` * `start()`/`cancel()`coroutines ```typescript const co = ex.coroutine(function* () { yield 100; }); co.start(); co.cancel(); await co; ``` * nested coroutines! (Nested coroutines do not start running, they are run with their parent) ```typescript const result = ex.coroutine(function* () { yield 100; yield* ex.coroutine(function* () { const elapsed = yield 99; }); yield 100; }); ```
- Loading branch information
Showing
4 changed files
with
240 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters