|
| 1 | +// Ripped from lib.es6.d.ts with addtions for atom |
| 2 | + |
| 3 | +/** |
| 4 | + * Represents the completion of an asynchronous operation |
| 5 | + */ |
| 6 | +interface Promise<T> { |
| 7 | + /** |
| 8 | + * Attaches callbacks for the resolution and/or rejection of the Promise. |
| 9 | + * @param onfulfilled The callback to execute when the Promise is resolved. |
| 10 | + * @param onrejected The callback to execute when the Promise is rejected. |
| 11 | + * @returns A Promise for the completion of which ever callback is executed. |
| 12 | + */ |
| 13 | + then<TResult>(onfulfilled?: (value: T) => TResult | Promise<TResult>, onrejected?: (reason: any) => TResult | Promise<TResult>): Promise<TResult>; |
| 14 | + |
| 15 | + /** |
| 16 | + * Attaches a callback for only the rejection of the Promise. |
| 17 | + * @param onrejected The callback to execute when the Promise is rejected. |
| 18 | + * @returns A Promise for the completion of the callback. |
| 19 | + */ |
| 20 | + catch(onrejected?: (reason: any) => T | Promise<T>): Promise<T>; |
| 21 | +} |
| 22 | + |
| 23 | +interface PromiseConstructor { |
| 24 | + /** |
| 25 | + * A reference to the prototype. |
| 26 | + */ |
| 27 | + prototype: Promise<any>; |
| 28 | + |
| 29 | + /** |
| 30 | + * Creates a new Promise. |
| 31 | + * @param init A callback used to initialize the promise. This callback is passed two arguments: |
| 32 | + * a resolve callback used resolve the promise with a value or the result of another promise, |
| 33 | + * and a reject callback used to reject the promise with a provided reason or error. |
| 34 | + */ |
| 35 | + new <T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>; |
| 36 | + |
| 37 | + <T>(init: (resolve: (value?: T | Promise<T>) => void, reject: (reason?: any) => void) => void): Promise<T>; |
| 38 | + |
| 39 | + /** |
| 40 | + * Creates a Promise that is resolved with an array of results when all of the provided Promises |
| 41 | + * resolve, or rejected when any Promise is rejected. |
| 42 | + * @param values An array of Promises. |
| 43 | + * @returns A new Promise. |
| 44 | + */ |
| 45 | + all<T>(values: (T | Promise<T>)[]): Promise<T[]>; |
| 46 | + |
| 47 | + /** |
| 48 | + * Creates a Promise that is resolved with an array of results when all of the provided Promises |
| 49 | + * resolve, or rejected when any Promise is rejected. |
| 50 | + * @param values An array of values. |
| 51 | + * @returns A new Promise. |
| 52 | + */ |
| 53 | + all(values: Promise<void>[]): Promise<void>; |
| 54 | + |
| 55 | + /** |
| 56 | + * Creates a Promise that is resolved or rejected when any of the provided Promises are resolved |
| 57 | + * or rejected. |
| 58 | + * @param values An array of Promises. |
| 59 | + * @returns A new Promise. |
| 60 | + */ |
| 61 | + race<T>(values: (T | Promise<T>)[]): Promise<T>; |
| 62 | + |
| 63 | + /** |
| 64 | + * Creates a new rejected promise for the provided reason. |
| 65 | + * @param reason The reason the promise was rejected. |
| 66 | + * @returns A new rejected Promise. |
| 67 | + */ |
| 68 | + reject(reason: any): Promise<void>; |
| 69 | + |
| 70 | + /** |
| 71 | + * Creates a new rejected promise for the provided reason. |
| 72 | + * @param reason The reason the promise was rejected. |
| 73 | + * @returns A new rejected Promise. |
| 74 | + */ |
| 75 | + reject<T>(reason: any): Promise<T>; |
| 76 | + |
| 77 | + /** |
| 78 | + * Creates a new resolved promise for the provided value. |
| 79 | + * @param value A promise. |
| 80 | + * @returns A promise whose internal state matches the provided promise. |
| 81 | + */ |
| 82 | + resolve<T>(value: T | Promise<T>): Promise<T>; |
| 83 | + |
| 84 | + /** |
| 85 | + * Creates a new resolved promise . |
| 86 | + * @returns A resolved promise. |
| 87 | + */ |
| 88 | + resolve(): Promise<void>; |
| 89 | + |
| 90 | + /// BAS ADDITIONS AFTER INSPECTION INTO ATOM |
| 91 | + defer<T>(): PromiseDeferred<T>; |
| 92 | +} |
| 93 | + |
| 94 | +interface PromiseDeferred<T> { |
| 95 | + promise: Promise<T>; resolve(value: T): any; reject(error: T): any; |
| 96 | +} |
| 97 | + |
| 98 | +declare var Promise: PromiseConstructor; |
0 commit comments