Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,36 @@ declare const pForever: {
@param fn - 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`.
@returns Fulfills when `fn` returns `pForever.end`, or rejects if any of the promises returned from `fn` rejects.

@example
```
import pForever = require('p-forever');

pForever(async i => {
i++;

if (i > 100) {
return pForever.end;
}

await createFixture(i);

return i;
}, 0);

// or
let i = 0;

pForever(async () => {
i++;

if (i > 100) {
return pForever.end;
}

await createFixture(i);
});
```
*/
<ValueType>(
fn: (
Expand All @@ -22,6 +52,9 @@ declare const pForever: {
Symbol used to end the loop.
*/
readonly end: unique symbol;

// TODO: Remove this for the next major release
default: typeof pForever;
};

export default pForever;
export = pForever;
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const pForever = async (fn, previousValue) => {
};

module.exports = pForever;
// TODO: Remove this for the next major release
module.exports.default = pForever;

module.exports.end = symbolEnd;
4 changes: 2 additions & 2 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import pForever from '.';
import {expectType} from 'tsd';
import pForever = require('.');

expectType<Promise<void>>(
pForever(i => {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -43,9 +43,9 @@
"bluebird"
],
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"delay": "^4.1.0",
"tsd-check": "^0.4.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Here we create some numbered fixtures. The `createFixture()` function returns a
```js
const pForever = require('p-forever');

pForever(i => {
pForever(async i => {
i++;

if (i > 100) {
Expand All @@ -39,7 +39,7 @@ const pForever = require('p-forever');

let i = 0;

pForever(() => {
pForever(async () => {
i++;

if (i > 100) {
Expand Down