mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-26 10:56:19 +08:00
Merge pull request #7229 from enicholson/bluebird-mapSeries
Added bluebird mapSeries definitions
This commit is contained in:
@@ -607,19 +607,19 @@ Promise.all([fooProm, barProm, fooProm]).then(result => {
|
||||
|
||||
//TODO fix collection inference
|
||||
|
||||
barArrProm = fooProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
|
||||
barArrProm = fooArrProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = fooProm.map<Foo, Bar>((item: Foo) => {
|
||||
barArrProm = fooArrProm.map<Foo, Bar>((item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
|
||||
barArrProm = fooProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
|
||||
barArrProm = fooArrProm.map<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
}, {
|
||||
concurrency: 1
|
||||
});
|
||||
barArrProm = fooProm.map<Foo, Bar>((item: Foo) => {
|
||||
barArrProm = fooArrProm.map<Foo, Bar>((item: Foo) => {
|
||||
return bar;
|
||||
}, {
|
||||
concurrency: 1
|
||||
@@ -627,10 +627,20 @@ barArrProm = fooProm.map<Foo, Bar>((item: Foo) => {
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
barProm = fooProm.reduce<Foo, Bar>((memo: Bar, item: Foo, index: number, arrayLength: number) => {
|
||||
barArrProm = fooArrProm.mapSeries<Foo, Bar>((item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = fooArrProm.mapSeries<Foo, Bar>((item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
barProm = fooArrProm.reduce<Foo, Bar>((memo: Bar, item: Foo, index: number, arrayLength: number) => {
|
||||
return memo;
|
||||
});
|
||||
barProm = fooProm.reduce<Foo, Bar>((memo: Bar, item: Foo) => {
|
||||
barProm = fooArrProm.reduce<Foo, Bar>((memo: Bar, item: Foo) => {
|
||||
return memo;
|
||||
}, bar);
|
||||
|
||||
@@ -1008,6 +1018,81 @@ barArrProm = Promise.map(fooArr, (item: Foo, index: number, arrayLength: number)
|
||||
concurrency: 1
|
||||
});
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// mapSeries()
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// fooThenArrThen
|
||||
|
||||
barArrProm = Promise.mapSeries(fooThenArrThen, (item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArrThen, (item: Foo) => {
|
||||
return barThen;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArrThen, (item: Foo, index: number, arrayLength: number) => {
|
||||
return barThen;
|
||||
});
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// fooArrThen
|
||||
|
||||
barArrProm = Promise.mapSeries(fooArrThen, (item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArrThen, (item: Foo) => {
|
||||
return barThen;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArrThen, (item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArrThen, (item: Foo, index: number, arrayLength: number) => {
|
||||
return barThen;
|
||||
});
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// fooThenArr
|
||||
|
||||
barArrProm = Promise.mapSeries(fooThenArr, (item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArr, (item: Foo) => {
|
||||
return barThen;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArr, (item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooThenArr, (item: Foo, index: number, arrayLength: number) => {
|
||||
return barThen;
|
||||
});
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// fooArr
|
||||
|
||||
barArrProm = Promise.mapSeries(fooArr, (item: Foo) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArr, (item: Foo) => {
|
||||
return barThen;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArr, (item: Foo, index: number, arrayLength: number) => {
|
||||
return bar;
|
||||
});
|
||||
barArrProm = Promise.mapSeries(fooArr, (item: Foo, index: number, arrayLength: number) => {
|
||||
return barThen;
|
||||
});
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
// reduce()
|
||||
|
||||
25
bluebird/bluebird.d.ts
vendored
25
bluebird/bluebird.d.ts
vendored
@@ -315,6 +315,12 @@ declare class Promise<R> implements Promise.Thenable<R>, Promise.Inspection<R> {
|
||||
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => Promise.Thenable<U>, options?: Promise.ConcurrencyOption): Promise<U[]>;
|
||||
map<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => U, options?: Promise.ConcurrencyOption): Promise<U[]>;
|
||||
|
||||
/**
|
||||
* Same as `Promise.mapSeries(thisPromise, mapper)`.
|
||||
*/
|
||||
// TODO type inference from array-resolving promise?
|
||||
mapSeries<Q, U>(mapper: (item: Q, index: number, arrayLength: number) => U|Promise.Thenable<U>): Promise<U[]>;
|
||||
|
||||
/**
|
||||
* Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too.
|
||||
*/
|
||||
@@ -573,6 +579,25 @@ declare class Promise<R> implements Promise.Thenable<R>, Promise.Inspection<R> {
|
||||
static map<R, U>(values: R[], mapper: (item: R, index: number, arrayLength: number) => Promise.Thenable<U>, options?: Promise.ConcurrencyOption): Promise<U[]>;
|
||||
static map<R, U>(values: R[], mapper: (item: R, index: number, arrayLength: number) => U, options?: Promise.ConcurrencyOption): Promise<U[]>;
|
||||
|
||||
/**
|
||||
* Similar to `map` with concurrency set to 1 but guaranteed to execute in sequential order
|
||||
*
|
||||
* If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well.
|
||||
*
|
||||
* *The original array is not modified.*
|
||||
*/
|
||||
// promise of array with promises of value
|
||||
static mapSeries<R, U>(values: Promise.Thenable<Promise.Thenable<R>[]>, mapper: (item: R, index: number, arrayLength: number) => U|Promise.Thenable<U>): Promise<U[]>;
|
||||
|
||||
// promise of array with values
|
||||
static mapSeries<R, U>(values: Promise.Thenable<R[]>, mapper: (item: R, index: number, arrayLength: number) => U|Promise.Thenable<U>): Promise<U[]>;
|
||||
|
||||
// array with promises of value
|
||||
static mapSeries<R, U>(values: Promise.Thenable<R>[], mapper: (item: R, index: number, arrayLength: number) => U|Promise.Thenable<U>): Promise<U[]>;
|
||||
|
||||
// array with values
|
||||
static mapSeries<R, U>(values: R[], mapper: (item: R, index: number, arrayLength: number) => U|Promise.Thenable<U>): Promise<U[]>;
|
||||
|
||||
/**
|
||||
* Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user