Skip to content

Instantly share code, notes, and snippets.

@saschanaz
Last active November 17, 2015 06:46
Show Gist options
  • Select an option

  • Save saschanaz/6cdf86c3f04153711623 to your computer and use it in GitHub Desktop.

Select an option

Save saschanaz/6cdf86c3f04153711623 to your computer and use it in GitHub Desktop.
ES20xx cancellable function proposal
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
// 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