Last active
November 17, 2015 06:46
-
-
Save saschanaz/6cdf86c3f04153711623 to your computer and use it in GitHub Desktop.
ES20xx cancellable function proposal
This file contains hidden or 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
| cancellable function foo() { // extends `async function` and introduces `queue` keyword | |
| let b = queue bar(); // can be auto canceled by cancelling foo | |
| b === cancellation // true when foo is canceled during bar call, otherwise false | |
| await bac(); // will not be auto canceled | |
| } | |
| let baz = foo(); | |
| baz.cancel(); | |
| baz === cancellation // true, new `cancellation` variable for function cancellation | |
| let { baw, bax } = await baz; | |
| baw === cancellation // true, cancellation.any is also cancellation | |
| let bay = (await baz)(); | |
| bay === cancellation // true, cancellation() is cancellation |
This file contains hidden or 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
| // Promise spec should be extended | |
| interface PromiseController { | |
| canceled: boolean; | |
| confirmCancellation: () => Promise<void>; | |
| } | |
| interface PromiseOptionBag { | |
| revert?: (status: string) => any | PromiseLike<any>; | |
| precancel?: () => any | PromiseLike<any>; | |
| deferCancellation?: boolean; | |
| } | |
| extended class Promise<T> { | |
| constructor( | |
| init: ( | |
| resolve: (value?: T | PromiseLike<T>) => Promise<void>, | |
| reject: (reason?: any) => void | PromiseLike<void>, | |
| controller: PromiseController | |
| ) => any, | |
| options: PromiseOptionBag | |
| ): Promise<T>; | |
| [Symbol.cancel](): Promise<void>; | |
| cancel(): Promise<void>; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment