Comparing version 2.1.0 to 3.0.0
@@ -1,36 +0,21 @@ | ||
declare const pSeries: { | ||
/** | ||
Run promise-returning & async functions in series. | ||
/** | ||
Run promise-returning & async functions in series. | ||
@param tasks - Functions are expected to return a value. If a Promise is returned, it's awaited before continuing with the next task. | ||
@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. | ||
@param tasks - Functions are expected to return a value. If a Promise is returned, it's awaited before continuing with the next task. | ||
@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. | ||
@example | ||
``` | ||
import pSeries = require('p-series'); | ||
import got = require('got'); | ||
@example | ||
``` | ||
import pSeries from 'p-series'; | ||
import got from 'got'; | ||
(async () => { | ||
const tasks = [ | ||
() => got('sindresorhus.com'), | ||
() => checkSomething(), | ||
() => doSomethingElse() | ||
]; | ||
const tasks = [ | ||
() => got('https://sindresorhus.com'), | ||
() => checkSomething(), | ||
() => doSomethingElse() | ||
]; | ||
console.log(await pSeries(tasks)); | ||
})(); | ||
``` | ||
*/ | ||
<ValueType>(tasks: Iterable<() => Promise<ValueType> | ValueType>): Promise< | ||
ValueType[] | ||
>; | ||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pSeries<ValueType>( | ||
// tasks: Iterable<() => Promise<ValueType> | ValueType> | ||
// ): Promise<ValueType[]>; | ||
// export = pSeries; | ||
default: typeof pSeries; | ||
}; | ||
export = pSeries; | ||
console.log(await pSeries(tasks)); | ||
``` | ||
*/ | ||
export default function pSeries<ValueType>(tasks: Iterable<() => Promise<ValueType> | ValueType>): Promise<ValueType[]>; |
27
index.js
@@ -1,26 +0,15 @@ | ||
'use strict'; | ||
const pReduce = require('p-reduce'); | ||
const is = require('@sindresorhus/is'); | ||
export default async function pSeries(tasks) { | ||
for (const task of tasks) { | ||
if (typeof task !== 'function') { | ||
throw new TypeError(`Expected task to be a \`Function\`, received \`${typeof task}\``); | ||
} | ||
} | ||
const pSeries = async tasks => { | ||
const results = []; | ||
for (const task of tasks) { | ||
const type = is(task); | ||
if (type !== 'Function') { | ||
throw new TypeError(`Expected task to be a \`Function\`, received \`${type}\``); | ||
} | ||
results.push(await task()); // eslint-disable-line no-await-in-loop | ||
} | ||
await pReduce(tasks, async (_, task) => { | ||
const value = await task(); | ||
results.push(value); | ||
}); | ||
return results; | ||
}; | ||
module.exports = pSeries; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pSeries; | ||
} |
{ | ||
"name": "p-series", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Run promise-returning & async functions in series", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-series", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -40,11 +43,7 @@ "scripts": { | ||
], | ||
"dependencies": { | ||
"@sindresorhus/is": "^0.15.0", | ||
"p-reduce": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.17.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
@@ -1,5 +0,7 @@ | ||
# p-series [![Build Status](https://travis-ci.org/sindresorhus/p-series.svg?branch=master)](https://travis-ci.org/sindresorhus/p-series) | ||
# p-series | ||
> Run promise-returning & async functions in series | ||
*Note:* You can just use `await` in a for-loop to get the same behavior. This package was useful before async/await existed. | ||
If you're doing the same work in each function, use [`p-each-series`](https://github.com/sindresorhus/p-each-series) instead. | ||
@@ -9,3 +11,2 @@ | ||
## Install | ||
@@ -17,21 +18,17 @@ | ||
## Usage | ||
```js | ||
const pSeries = require('p-series'); | ||
const got = require('got'); | ||
import pSeries from 'p-series'; | ||
import got from 'got'; | ||
(async () => { | ||
const tasks = [ | ||
() => got('sindresorhus.com'), | ||
() => checkSomething(), | ||
() => doSomethingElse() | ||
]; | ||
const tasks = [ | ||
() => got('https://sindresorhus.com'), | ||
() => checkSomething(), | ||
() => doSomethingElse() | ||
]; | ||
console.log(await pSeries(tasks)); | ||
})(); | ||
console.log(await pSeries(tasks)); | ||
``` | ||
## API | ||
@@ -49,3 +46,2 @@ | ||
## Related | ||
@@ -57,6 +53,1 @@ | ||
- [More…](https://github.com/sindresorhus/promise-fun) | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
Yes
4610
29
50
- Removed@sindresorhus/is@^0.15.0
- Removedp-reduce@^2.1.0
- Removed@sindresorhus/is@0.15.0(transitive)
- Removedp-reduce@2.1.0(transitive)