mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
Q: adding inspect() method, changing return type of getSettled
As per documentation: https://github.com/kriskowal/q/wiki/API-Reference#promiseallsettled https://github.com/kriskowal/q/wiki/API-Reference#promiseinspect
This commit is contained in:
17
q/Q-tests.ts
17
q/Q-tests.ts
@@ -90,4 +90,19 @@ Q.all<number>(myNums).then(nums => nums.map(Math.round));
|
||||
Q.fbind((dateString) => new Date(dateString), "11/11/1991")().then(d => d.toLocaleDateString());
|
||||
|
||||
Q.when(8, num => num + "!");
|
||||
Q.when(Q(8), num => num + "!").then(str => str.split(','));
|
||||
Q.when(Q(8), num => num + "!").then(str => str.split(','));
|
||||
|
||||
declare function saveToDisk(): Q.Promise<any>;
|
||||
declare function saveToCloud(): Q.Promise<any>;
|
||||
Q.allSettled([saveToDisk(), saveToCloud()]).spread(function (disk, cloud) {
|
||||
console.log("saved to disk:", disk.state === "fulfilled");
|
||||
console.log("saved to cloud:", cloud.state === "fulfilled");
|
||||
|
||||
if (disk.state === "fulfilled") {
|
||||
console.log("value was " + disk.value);
|
||||
}
|
||||
else if (disk.state === "rejected") {
|
||||
console.log("rejected because " + disk.reason);
|
||||
}
|
||||
}).done();
|
||||
|
||||
|
||||
14
q/Q.d.ts
vendored
14
q/Q.d.ts
vendored
@@ -60,6 +60,14 @@ declare module Q {
|
||||
isPending(): boolean;
|
||||
|
||||
valueOf(): any;
|
||||
|
||||
inspect(): PromiseState<T>;
|
||||
}
|
||||
|
||||
interface PromiseState<T> {
|
||||
state: string /* "fulfilled", "rejected", "pending" */;
|
||||
value?: T;
|
||||
reason?: any;
|
||||
}
|
||||
|
||||
// if no fulfill, reject, or progress provided, returned promise will be of same type
|
||||
@@ -96,8 +104,8 @@ declare module Q {
|
||||
export function all<T>(promises: any[]): Promise<T[]>;
|
||||
export function all<T>(promises: IPromise<T>[]): Promise<T[]>;
|
||||
|
||||
export function allSettled<T>(promises: any[]): Promise<Promise<T>[]>;
|
||||
export function allSettled<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
|
||||
export function allSettled<T>(promises: any[]): Promise<PromiseState<T>[]>;
|
||||
export function allSettled<T>(promises: IPromise<T>[]): Promise<PromiseState<T>[]>;
|
||||
|
||||
export function allResolved<T>(promises: any[]): Promise<Promise<T>[]>;
|
||||
export function allResolved<T>(promises: IPromise<T>[]): Promise<Promise<T>[]>;
|
||||
@@ -145,4 +153,4 @@ declare module Q {
|
||||
|
||||
declare module "q" {
|
||||
export = Q;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user