bluebird: Promise.all takes different types of promises

This commit is contained in:
heycalmdown
2015-10-29 07:46:59 +09:00
parent 62eedc3121
commit b024a04b8a
2 changed files with 34 additions and 0 deletions
+29
View File
@@ -36,6 +36,9 @@ interface Foo {
interface Bar {
bar(): string;
}
interface Baz {
baz(): string;
}
// - - - - - - - - - - - - - - - - -
@@ -61,6 +64,7 @@ interface StrBarArrMap {
var foo: Foo;
var bar: Bar;
var baz: Baz;
var fooArr: Foo[];
var barArr: Bar[];
@@ -76,6 +80,7 @@ var voidProm: Promise<void>;
var fooProm: Promise<Foo>;
var barProm: Promise<Bar>;
var bazProm: Promise<Baz>;
// - - - - - - - - - - - - - - - - -
@@ -499,6 +504,30 @@ barProm = fooProm.race<Bar>();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Promise.all([fooProm, barProm]).then(result => {
result[0].foo();
result[1].bar();
});
Promise.all([fooProm, fooProm]).then(result => {
result[0].foo();
result[1].foo();
});
Promise.all([fooProm, barProm, bazProm]).then(result => {
result[0].foo();
result[1].bar();
result[2].baz();
});
Promise.all([fooProm, barProm, fooProm]).then(result => {
result[0].foo();
result[1].bar();
result[2].foo();
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//TODO fix collection inference
barArrProm = fooProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
+5
View File
@@ -464,6 +464,11 @@ declare class Promise<R> implements Promise.Thenable<R>, Promise.Inspection<R> {
static all<R>(values: Promise.Thenable<R[]>): Promise<R[]>;
// array with promises of value
static all<R>(values: Promise.Thenable<R>[]): Promise<R[]>;
// array with promises of different types
static all<T1, T2>(values: [Promise.Thenable<T1>, Promise.Thenable<T2>]): Promise<[T1, T2]>;
static all<T1, T2, T3>(values: [Promise.Thenable<T1>, Promise.Thenable<T2>, Promise.Thenable<T3>]): Promise<[T1, T2, T3]>;
static all<T1, T2, T3, T4>(values: [Promise.Thenable<T1>, Promise.Thenable<T2>, Promise.Thenable<T3>, Promise.Thenable<T4>]): Promise<[T1, T2, T3, T4]>;
static all<T1, T2, T3, T4, T5>(values: [Promise.Thenable<T1>, Promise.Thenable<T2>, Promise.Thenable<T3>, Promise.Thenable<T4>, Promise.Thenable<T5>]): Promise<[T1, T2, T3, T4, T5]>;
// array with values
static all<R>(values: R[]): Promise<R[]>;