>(): P;
-
- /**
- * Return a resolved promise wrapped in an ExtensiblePromise
- *
- * @param value The value to resolve the promise with
- *
- * @returns An extensible promise
- */
- static resolve>(value: T | PromiseLike): P;
- static resolve(value?: any | PromiseLike): ExtensiblePromise {
- return new this((resolve, reject) => resolve(value));
- }
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: DictionaryOfPromises): ExtensiblePromise<{ [key: string]: T }>;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: (T | Thenable)[]): ExtensiblePromise;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: T | Thenable): ExtensiblePromise;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: ListOfPromises): ExtensiblePromise;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(
- iterable: DictionaryOfPromises | ListOfPromises
- ): ExtensiblePromise {
- if (!isArrayLike(iterable) && !isIterable(iterable)) {
- const promiseKeys = Object.keys(iterable);
-
- return new this((resolve, reject) => {
- Promise.all(promiseKeys.map((key) => iterable[key])).then((promiseResults: T[]) => {
- const returnValue: { [key: string]: T } = {};
-
- promiseResults.forEach((value: T, index: number) => {
- returnValue[promiseKeys[index]] = value;
- });
-
- resolve(returnValue);
- }, reject);
- });
- }
-
- return new this((resolve, reject) => {
- Promise.all(unwrapPromises(>iterable)).then(resolve, reject);
- });
- }
-
- /**
- * Return a ExtensiblePromise that resolves when one of the passed in objects have resolved
- *
- * @param iterable An iterable of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns {ExtensiblePromise}
- */
- static race(iterable: Iterable> | (T | PromiseLike)[]): ExtensiblePromise {
- return new this((resolve, reject) => {
- Promise.race(unwrapPromises(iterable)).then(resolve, reject);
- });
- }
-
- /**
- * @type {Promise}
- * The wrapped promise
- */
- readonly _promise: Promise;
-
- /**
- * Creates a new extended Promise.
- *
- * @constructor
- *
- * @param executor
- * The executor function is called immediately when the Promise is instantiated. It is responsible for
- * starting the asynchronous operation when it is invoked.
- *
- * The executor must call either the passed `resolve` function when the asynchronous operation has completed
- * successfully, or the `reject` function when the operation fails.
- */
- constructor(executor: Executor) {
- this._promise = new Promise(executor);
- }
-
- /**
- * Adds a callback to be invoked when the wrapped Promise is rejected.
- *
- * @param {Function} onRejected A function to call to handle the error. The parameter to the function will be the caught error.
- *
- * @returns {ExtensiblePromise}
- */
- catch(
- onRejected?: ((reason: any) => TResult | PromiseLike) | undefined | null
- ): ExtensiblePromise {
- return this.then(undefined, onRejected);
- }
-
- /**
- * Adds a callback to be invoked when the wrapped Promise resolves or is rejected.
- *
- * @param {Function} onFulfilled A function to call to handle the resolution. The paramter to the function will be the resolved value, if any.
- * @param {Function} onRejected A function to call to handle the error. The parameter to the function will be the caught error.
- *
- * @returns {ExtensiblePromise}
- */
- then(
- onFulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null,
- onRejected?: ((reason: any) => TResult2 | PromiseLike | void) | undefined | null
- ): ExtensiblePromise {
- const executor: Executor = (resolve, reject) => {
- function handler(rejected: boolean, valueOrError: T | TResult1 | Error) {
- const callback: ((value: any) => any) | null | undefined = rejected ? onRejected : onFulfilled;
-
- if (typeof callback === 'function') {
- try {
- resolve(callback(valueOrError));
- } catch (error) {
- reject(error);
- }
- } else if (rejected) {
- reject(valueOrError);
- } else {
- resolve(valueOrError as TResult1);
- }
- }
-
- this._promise.then(handler.bind(null, false), handler.bind(null, true));
- };
-
- return new (this.constructor as typeof ExtensiblePromise)(executor);
- }
-
- readonly [Symbol.toStringTag]: 'Promise';
-}
-
-export default ExtensiblePromise;
diff --git a/src/lib/core/src/async/Task.ts b/src/lib/core/src/async/Task.ts
deleted file mode 100644
index e555533..0000000
--- a/src/lib/core/src/async/Task.ts
+++ /dev/null
@@ -1,384 +0,0 @@
-import { Thenable } from '@dojo/shim/interfaces';
-import { isArrayLike, isIterable, Iterable } from '@dojo/shim/iterator';
-import { Executor } from '@dojo/shim/Promise';
-import ExtensiblePromise, { DictionaryOfPromises, ListOfPromises, unwrapPromises } from './ExtensiblePromise';
-
-/**
- * Describe the internal state of a task.
- */
-export const enum State {
- Fulfilled = 0,
- Pending = 1,
- Rejected = 2,
- Canceled = 3
-}
-
-/**
- * A type guard that determines if `value` is a `Task`
- * @param value The value to guard
- */
-export function isTask(value: any): value is Task {
- return Boolean(value && typeof value.cancel === 'function' && Array.isArray(value.children) && isThenable(value));
-}
-
-/**
- * Returns true if a given value has a `then` method.
- * @param {any} value The value to check if is Thenable
- * @returns {is Thenable} A type guard if the value is thenable
- */
-export function isThenable(value: any): value is Thenable {
- return value && typeof value.then === 'function';
-}
-
-/**
- * Task is an extension of Promise that supports cancellation and the Task#finally method.
- */
-export class Task extends ExtensiblePromise {
- /**
- * Return a Task that resolves when one of the passed in objects have resolved
- *
- * @param iterable An iterable of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns {Task}
- */
- static race(iterable: Iterable> | (T | Thenable)[]): Task {
- return new this((resolve, reject) => {
- Promise.race(unwrapPromises(iterable)).then(resolve, reject);
- });
- }
-
- /**
- * Return a rejected promise wrapped in a Task
- *
- * @param reason The reason for the rejection
- * @returns A task
- */
- static reject(reason?: Error): Task {
- return new this((resolve, reject) => reject(reason));
- }
-
- /**
- * Return a resolved task.
- *
- * @param value The value to resolve with
- *
- * @return A task
- */
- public static resolve(): Task;
-
- /**
- * Return a resolved task.
- *
- * @param value The value to resolve with
- *
- * @return A task
- */
- public static resolve(value: T | Thenable): Task;
-
- /**
- * Return a resolved task.
- *
- * @param value The value to resolve with
- *
- * @return A task
- */
- public static resolve(value?: any): Task {
- return new this((resolve, reject) => resolve(value));
- }
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: DictionaryOfPromises): Task<{ [key: string]: T }>;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: (T | Thenable)[]): Task;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: T | Thenable): Task;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: ListOfPromises): Task;
-
- /**
- * Return a ExtensiblePromise that resolves when all of the passed in objects have resolved. When used with a key/value
- * pair, the returned promise's argument is a key/value pair of the original keys with their resolved values.
- *
- * @example
- * ExtensiblePromise.all({ one: 1, two: 2 }).then(results => console.log(results));
- * // { one: 1, two: 2 }
- *
- * @param iterable An iterable of values to resolve, or a key/value pair of values to resolve. These can be Promises, ExtensiblePromises, or other objects
- * @returns An extensible promise
- */
- static all(iterable: DictionaryOfPromises | ListOfPromises): Task {
- return new Task(
- (resolve, reject) => {
- super.all(iterable).then(resolve, reject);
- },
- () => {
- if (isArrayLike(iterable)) {
- for (let i = 0; i < iterable.length; i++) {
- const promiseLike = iterable[i];
-
- if (isTask(promiseLike)) {
- promiseLike.cancel();
- }
- }
- } else if (isIterable(iterable)) {
- for (const promiseLike of iterable) {
- if (isTask(promiseLike)) {
- promiseLike.cancel();
- }
- }
- } else {
- Object.keys(iterable).forEach((key: any) => {
- const promiseLike = iterable[key];
-
- if (isTask(promiseLike)) {
- promiseLike.cancel();
- }
- });
- }
- }
- );
- }
-
- /**
- * A cancelation handler that will be called if this task is canceled.
- */
- private canceler: () => void;
-
- /**
- * Children of this Task (i.e., Tasks that were created from this Task with `then` or `catch`).
- */
- private readonly children: Task[];
-
- /**
- * The finally callback for this Task (if it was created by a call to `finally`).
- */
- private _finally: undefined | (() => void);
-
- /**
- * The state of the task
- */
- protected _state: State;
-
- get state() {
- return this._state;
- }
-
- /**
- * @constructor
- *
- * Create a new task. Executor is run immediately. The canceler will be called when the task is canceled.
- *
- * @param executor Method that initiates some task
- * @param canceler Method to call when the task is canceled
- *
- */
- constructor(executor: Executor