Run promise-returning & async functions until you end it
Think of it like an async version of while (true) {}.
$ npm install p-forever
Here we create some numbered fixtures. The createFixture() function returns a Promise.
import pForever from 'p-forever';
pForever(async index => {
index++;
if (index > 100) {
return pForever.end;
}
await createFixture(index);
return index;
}, 0);or
import pForever from 'p-forever';
let index = 0;
pForever(async () => {
index++;
if (index > 100) {
return pForever.end;
}
await createFixture(index);
});Returns a Promise that is fulfilled when fn returns pForever.end, or rejects if any of the promises returned from fn rejects.
Type: Function
Receives the previously returned value. If a Promise is returned, it's awaited before calling fn again.
Initial value to pass to fn.
Symbol used to end the loop.