Comparing version 2.1.0 to 3.0.0
declare const pForever: { | ||
/** | ||
Symbol used to end the loop. | ||
*/ | ||
readonly end: unique symbol; | ||
/** | ||
Run promise-returning & async functions until you end it. | ||
@param fn - Receives the previously returned value. If a `Promise` is returned, it's awaited before calling `fn` again. | ||
@param function_ - Receives the previously returned value. If a `Promise` is returned, it's awaited before calling `fn` again. | ||
@param initialValue - Initial value to pass to `fn`. | ||
@@ -11,27 +16,27 @@ @returns Fulfills when `fn` returns `pForever.end`, or rejects if any of the promises returned from `fn` rejects. | ||
``` | ||
import pForever = require('p-forever'); | ||
import pForever from 'p-forever'; | ||
pForever(async i => { | ||
i++; | ||
pForever(async index => { | ||
index++; | ||
if (i > 100) { | ||
if (index > 100) { | ||
return pForever.end; | ||
} | ||
await createFixture(i); | ||
await createFixture(index); | ||
return i; | ||
return index; | ||
}, 0); | ||
// or | ||
let i = 0; | ||
let index = 0; | ||
pForever(async () => { | ||
i++; | ||
index++; | ||
if (i > 100) { | ||
if (index > 100) { | ||
return pForever.end; | ||
} | ||
await createFixture(i); | ||
await createFixture(index); | ||
}); | ||
@@ -41,3 +46,3 @@ ``` | ||
<ValueType>( | ||
fn: ( | ||
function_: ( | ||
previousValue?: ValueType | ||
@@ -47,3 +52,3 @@ ) => ValueType | PromiseLike<ValueType> | typeof pForever.end | ||
<ValueType>( | ||
fn: ( | ||
function_: ( | ||
previousValue: ValueType | ||
@@ -53,12 +58,4 @@ ) => ValueType | PromiseLike<ValueType> | typeof pForever.end, | ||
): Promise<void>; | ||
/** | ||
Symbol used to end the loop. | ||
*/ | ||
readonly end: unique symbol; | ||
// TODO: Remove this for the next major release | ||
default: typeof pForever; | ||
}; | ||
export = pForever; | ||
export default pForever; |
17
index.js
@@ -1,18 +0,15 @@ | ||
'use strict'; | ||
const symbolEnd = Symbol('pForever.end'); | ||
const endSymbol = Symbol('pForever.end'); | ||
const pForever = async (fn, previousValue) => { | ||
const newValue = await fn(await previousValue); | ||
const pForever = async (function_, previousValue) => { | ||
const newValue = await function_(await previousValue); | ||
if (newValue === symbolEnd) { | ||
if (newValue === endSymbol) { | ||
return; | ||
} | ||
return pForever(fn, newValue); | ||
return pForever(function_, newValue); | ||
}; | ||
module.exports = pForever; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pForever; | ||
pForever.end = endSymbol; | ||
module.exports.end = symbolEnd; | ||
export default pForever; |
{ | ||
"name": "p-forever", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Run promise-returning & async functions repeatedly until you end it", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-forever", | ||
"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" | ||
}, | ||
@@ -46,7 +49,7 @@ "scripts": { | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"ava": "^3.15.0", | ||
"delay": "^5.0.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# p-forever [![Build Status](https://travis-ci.org/sindresorhus/p-forever.svg?branch=master)](https://travis-ci.org/sindresorhus/p-forever) | ||
# p-forever | ||
@@ -7,3 +7,2 @@ > Run promise-returning & async functions until you end it | ||
## Install | ||
@@ -15,3 +14,2 @@ | ||
## Usage | ||
@@ -22,14 +20,14 @@ | ||
```js | ||
const pForever = require('p-forever'); | ||
import pForever from 'p-forever'; | ||
pForever(async i => { | ||
i++; | ||
pForever(async index => { | ||
index++; | ||
if (i > 100) { | ||
if (index > 100) { | ||
return pForever.end; | ||
} | ||
await createFixture(i); | ||
await createFixture(index); | ||
return i; | ||
return index; | ||
}, 0); | ||
@@ -41,14 +39,14 @@ ``` | ||
```js | ||
const pForever = require('p-forever'); | ||
import pForever from 'p-forever'; | ||
let i = 0; | ||
let index = 0; | ||
pForever(async () => { | ||
i++; | ||
index++; | ||
if (i > 100) { | ||
if (index > 100) { | ||
return pForever.end; | ||
} | ||
await createFixture(i); | ||
await createFixture(index); | ||
}); | ||
@@ -60,3 +58,3 @@ ``` | ||
### pForever(fn, [initialValue]) | ||
### pForever(fn, initialValue?) | ||
@@ -79,3 +77,2 @@ Returns a `Promise` that is fulfilled when `fn` returns `pForever.end`, or rejects if any of the promises returned from `fn` rejects. | ||
## Related | ||
@@ -86,6 +83,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
Yes
4928
55
77