Skip to content

Commit 64d1c5c

Browse files
BendingBendersindresorhus
authored andcommitted
Require Node.js 6, add TypeScript definition, update dependencies (#4)
1 parent 0483736 commit 64d1c5c

File tree

10 files changed

+225
-11
lines changed

10 files changed

+225
-11
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{package.json,*.yml}]
10+
[*.yml]
1111
indent_style = space
1212
indent_size = 2

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3+
- '10'
4+
- '8'
35
- '6'
4-
- '4'

index.d.ts

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
export interface Options {
2+
/**
3+
* Number of concurrent pending promises. Minimum: `1`.
4+
*
5+
* @default Infinity
6+
*/
7+
concurrency?: number;
8+
}
9+
10+
export type PromiseFactory<T> = () => PromiseLike<T>;
11+
12+
/**
13+
* Run promise-returning & async functions concurrently with optional limited concurrency.
14+
*
15+
* @param tasks - Iterable with promise-returning/async functions.
16+
* @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.
17+
*/
18+
declare function pAll<
19+
Result1,
20+
Result2,
21+
Result3,
22+
Result4,
23+
Result5,
24+
Result6,
25+
Result7,
26+
Result8,
27+
Result9,
28+
Result10
29+
>(
30+
tasks: [
31+
PromiseFactory<Result1>,
32+
PromiseFactory<Result2>,
33+
PromiseFactory<Result3>,
34+
PromiseFactory<Result4>,
35+
PromiseFactory<Result5>,
36+
PromiseFactory<Result6>,
37+
PromiseFactory<Result7>,
38+
PromiseFactory<Result8>,
39+
PromiseFactory<Result9>,
40+
PromiseFactory<Result10>
41+
],
42+
options?: Options
43+
): Promise<
44+
[
45+
Result1,
46+
Result2,
47+
Result3,
48+
Result4,
49+
Result5,
50+
Result6,
51+
Result7,
52+
Result8,
53+
Result9,
54+
Result10
55+
]
56+
>;
57+
declare function pAll<
58+
Result1,
59+
Result2,
60+
Result3,
61+
Result4,
62+
Result5,
63+
Result6,
64+
Result7,
65+
Result8,
66+
Result9
67+
>(
68+
tasks: [
69+
PromiseFactory<Result1>,
70+
PromiseFactory<Result2>,
71+
PromiseFactory<Result3>,
72+
PromiseFactory<Result4>,
73+
PromiseFactory<Result5>,
74+
PromiseFactory<Result6>,
75+
PromiseFactory<Result7>,
76+
PromiseFactory<Result8>,
77+
PromiseFactory<Result9>
78+
],
79+
options?: Options
80+
): Promise<
81+
[
82+
Result1,
83+
Result2,
84+
Result3,
85+
Result4,
86+
Result5,
87+
Result6,
88+
Result7,
89+
Result8,
90+
Result9
91+
]
92+
>;
93+
declare function pAll<
94+
Result1,
95+
Result2,
96+
Result3,
97+
Result4,
98+
Result5,
99+
Result6,
100+
Result7,
101+
Result8
102+
>(
103+
tasks: [
104+
PromiseFactory<Result1>,
105+
PromiseFactory<Result2>,
106+
PromiseFactory<Result3>,
107+
PromiseFactory<Result4>,
108+
PromiseFactory<Result5>,
109+
PromiseFactory<Result6>,
110+
PromiseFactory<Result7>,
111+
PromiseFactory<Result8>
112+
],
113+
options?: Options
114+
): Promise<
115+
[Result1, Result2, Result3, Result4, Result5, Result6, Result7, Result8]
116+
>;
117+
declare function pAll<
118+
Result1,
119+
Result2,
120+
Result3,
121+
Result4,
122+
Result5,
123+
Result6,
124+
Result7
125+
>(
126+
tasks: [
127+
PromiseFactory<Result1>,
128+
PromiseFactory<Result2>,
129+
PromiseFactory<Result3>,
130+
PromiseFactory<Result4>,
131+
PromiseFactory<Result5>,
132+
PromiseFactory<Result6>,
133+
PromiseFactory<Result7>
134+
],
135+
options?: Options
136+
): Promise<[Result1, Result2, Result3, Result4, Result5, Result6, Result7]>;
137+
declare function pAll<Result1, Result2, Result3, Result4, Result5, Result6>(
138+
tasks: [
139+
PromiseFactory<Result1>,
140+
PromiseFactory<Result2>,
141+
PromiseFactory<Result3>,
142+
PromiseFactory<Result4>,
143+
PromiseFactory<Result5>,
144+
PromiseFactory<Result6>
145+
],
146+
options?: Options
147+
): Promise<[Result1, Result2, Result3, Result4, Result5, Result6]>;
148+
declare function pAll<Result1, Result2, Result3, Result4, Result5>(
149+
tasks: [
150+
PromiseFactory<Result1>,
151+
PromiseFactory<Result2>,
152+
PromiseFactory<Result3>,
153+
PromiseFactory<Result4>,
154+
PromiseFactory<Result5>
155+
],
156+
options?: Options
157+
): Promise<[Result1, Result2, Result3, Result4, Result5]>;
158+
declare function pAll<Result1, Result2, Result3, Result4>(
159+
tasks: [
160+
PromiseFactory<Result1>,
161+
PromiseFactory<Result2>,
162+
PromiseFactory<Result3>,
163+
PromiseFactory<Result4>
164+
],
165+
options?: Options
166+
): Promise<[Result1, Result2, Result3, Result4]>;
167+
declare function pAll<Result1, Result2, Result3>(
168+
tasks: [
169+
PromiseFactory<Result1>,
170+
PromiseFactory<Result2>,
171+
PromiseFactory<Result3>
172+
],
173+
options?: Options
174+
): Promise<[Result1, Result2, Result3]>;
175+
declare function pAll<Result1, Result2>(
176+
tasks: [PromiseFactory<Result1>, PromiseFactory<Result2>],
177+
options?: Options
178+
): Promise<[Result1, Result2]>;
179+
declare function pAll<Result1>(
180+
tasks: [PromiseFactory<Result1>],
181+
options?: Options
182+
): Promise<[Result1]>;
183+
declare function pAll<TAll>(
184+
tasks: Iterable<PromiseFactory<TAll>> | PromiseFactory<TAll>[],
185+
options?: Options
186+
): Promise<TAll[]>;
187+
188+
export default pAll;

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
const pMap = require('p-map');
33

44
module.exports = (iterable, opts) => pMap(iterable, el => el(), opts);
5+
module.exports.default = module.exports;

index.test-d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {expectType} from 'tsd-check';
2+
import pAll from '.';
3+
4+
const actions: [
5+
() => Promise<string>,
6+
() => Promise<string>,
7+
() => Promise<void>,
8+
() => Promise<number>
9+
] = [
10+
() => Promise.resolve('sindresorhus.com'),
11+
() => Promise.resolve('ava.li'),
12+
() => Promise.resolve(),
13+
() => Promise.resolve(1)
14+
];
15+
16+
const result = await pAll(actions, {concurrency: 2});
17+
18+
expectType<string>(result[0]);
19+
expectType<string>(result[1]);
20+
expectType<void>(result[2]);
21+
expectType<number>(result[3]);

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=4"
13+
"node": ">=6"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd-check"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"promise",
@@ -42,12 +43,13 @@
4243
"bluebird"
4344
],
4445
"dependencies": {
45-
"p-map": "^1.0.0"
46+
"p-map": "^2.0.0"
4647
},
4748
"devDependencies": {
48-
"ava": "*",
49+
"ava": "^1.2.1",
4950
"delay": "^1.3.1",
50-
"xo": "*"
51+
"tsd-check": "^0.3.0",
52+
"xo": "^0.24.0"
5153
},
5254
"xo": {
5355
"esnext": true

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava';
22
import delay from 'delay';
3-
import m from './';
3+
import m from '.';
44

55
// See `p-map` for more comprehensive tests
66
test('main', async t => {

0 commit comments

Comments
 (0)