0.4.2 • Published 1 year ago

run-forever v0.4.2

Weekly downloads
4
License
ISC
Repository
github
Last release
1 year ago

run-forever

Implement run forever by setImmediate() instead of a recursive function which may cause "memory stack overflow"

Install

npm install run-forever --save

Usage

more example

forever(fn, previousValue, callback)

Parameters:

parametertypedescription
fn(previousValue) => PromiseExecution function. forever() exits if returns a promise with END resolved data.
previousValueanyoptional. Initialize a previous value to pass through executions
callback(err, previousValue) => voidoptional. Invoke the callback if forever() exists
import {forever, END} from 'run-forever';
forever(async i => {
  i++;
  return i === 10 ? END : i;
},
  0,
  (err, previousValue) => {
    if(err) console.error(err);
    else console.log(previousValue);
  }
);
console.log('start');

foreverPromise(fn, previousValue)

Parameters:

parametertypedescription
fn(previousValue) => PromiseExecution function. forever() exits if returns a promise with END resolved data.
previousValueanyoptional. Initialize a previous value to pass through executions

Return: Promise with previousValue data

import { foreverPromise, END } from 'run-forever';

(async () => {
  console.log('start');
  const previousValue = await foreverPromise(async (count) => {
    count++;
    return count === 10 ? END : count;
  }, 0);
  console.log('forever done ' + previousValue);
})().catch(console.error);
0.3.9

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.3.4

1 year ago

0.4.2

1 year ago

0.3.3

1 year ago

0.2.0

3 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago