-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require Node.js 6, add TypeScript definition, update dependencies #4
Merged
sindresorhus
merged 2 commits into
sindresorhus:master
from
BendingBender:typescript-defs
Mar 2, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
export interface Options { | ||
/** | ||
* Number of concurrent pending promises. Minimum: `1`. | ||
* | ||
* @default Infinity | ||
*/ | ||
concurrency?: number; | ||
} | ||
|
||
export type PromiseFactory<T> = () => PromiseLike<T>; | ||
|
||
/** | ||
* Run promise-returning & async functions concurrently with optional limited concurrency. | ||
* | ||
* @param tasks - Iterable with promise-returning/async functions. | ||
* @returns A `Promise` that is fulfilled when all promises returned from calling the functions in `tasks` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values in `tasks` order. | ||
*/ | ||
declare function pAll< | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7, | ||
Result8, | ||
Result9, | ||
Result10 | ||
>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5>, | ||
PromiseFactory<Result6>, | ||
PromiseFactory<Result7>, | ||
PromiseFactory<Result8>, | ||
PromiseFactory<Result9>, | ||
PromiseFactory<Result10> | ||
], | ||
options?: Options | ||
): Promise< | ||
[ | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7, | ||
Result8, | ||
Result9, | ||
Result10 | ||
] | ||
>; | ||
declare function pAll< | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7, | ||
Result8, | ||
Result9 | ||
>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5>, | ||
PromiseFactory<Result6>, | ||
PromiseFactory<Result7>, | ||
PromiseFactory<Result8>, | ||
PromiseFactory<Result9> | ||
], | ||
options?: Options | ||
): Promise< | ||
[ | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7, | ||
Result8, | ||
Result9 | ||
] | ||
>; | ||
declare function pAll< | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7, | ||
Result8 | ||
>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5>, | ||
PromiseFactory<Result6>, | ||
PromiseFactory<Result7>, | ||
PromiseFactory<Result8> | ||
], | ||
options?: Options | ||
): Promise< | ||
[Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8] | ||
>; | ||
declare function pAll< | ||
Result1, | ||
Result2, | ||
Result3, | ||
Result4, | ||
Result5, | ||
Result6, | ||
Result7 | ||
>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5>, | ||
PromiseFactory<Result6>, | ||
PromiseFactory<Result7> | ||
], | ||
options?: Options | ||
): Promise<[Result1, Result2, Result3, Result4, Result5, Result6, Result7]>; | ||
declare function pAll<Result1, Result2, Result3, Result4, Result5, Result6>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5>, | ||
PromiseFactory<Result6> | ||
], | ||
options?: Options | ||
): Promise<[Result1, Result2, Result3, Result4, Result5, Result6]>; | ||
declare function pAll<Result1, Result2, Result3, Result4, Result5>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4>, | ||
PromiseFactory<Result5> | ||
], | ||
options?: Options | ||
): Promise<[Result1, Result2, Result3, Result4, Result5]>; | ||
declare function pAll<Result1, Result2, Result3, Result4>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3>, | ||
PromiseFactory<Result4> | ||
], | ||
options?: Options | ||
): Promise<[Result1, Result2, Result3, Result4]>; | ||
declare function pAll<Result1, Result2, Result3>( | ||
tasks: [ | ||
PromiseFactory<Result1>, | ||
PromiseFactory<Result2>, | ||
PromiseFactory<Result3> | ||
], | ||
options?: Options | ||
): Promise<[Result1, Result2, Result3]>; | ||
declare function pAll<Result1, Result2>( | ||
tasks: [PromiseFactory<Result1>, PromiseFactory<Result2>], | ||
options?: Options | ||
): Promise<[Result1, Result2]>; | ||
declare function pAll<Result1>( | ||
tasks: [PromiseFactory<Result1>], | ||
options?: Options | ||
): Promise<[Result1]>; | ||
declare function pAll<TAll>( | ||
tasks: Iterable<PromiseFactory<TAll>> | PromiseFactory<TAll>[], | ||
options?: Options | ||
): Promise<TAll[]>; | ||
|
||
export default pAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {expectType} from 'tsd-check'; | ||
import pAll from '.'; | ||
|
||
const actions: [ | ||
() => Promise<string>, | ||
() => Promise<string>, | ||
() => Promise<void>, | ||
() => Promise<number> | ||
] = [ | ||
() => Promise.resolve('sindresorhus.com'), | ||
() => Promise.resolve('ava.li'), | ||
() => Promise.resolve(), | ||
() => Promise.resolve(1) | ||
]; | ||
|
||
const result = await pAll(actions, {concurrency: 2}); | ||
|
||
expectType<string>(result[0]); | ||
expectType<string>(result[1]); | ||
expectType<void>(result[2]); | ||
expectType<number>(result[3]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there are more than 10 inputs? There must be a better way of achieving this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a not-so-convenient fallback for any number of parameters:
ATM, TypeScript doesn't have a better way to describe this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if there's any TS issue for this? Seems like a very big limitation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you've already found it in sindresorhus/p-progress#10, but for anyone else that's reading this there's a related issue in microsoft/TypeScript#5453, which was addressed via variadic tuple types, but unclear whether it solves this yet
Experimental PR to add variadic tuple to Promise.all microsoft/TypeScript#39796