0.4.2 • Published 3 years ago

run-forever v0.4.2

Weekly downloads
4
License
ISC
Repository
github
Last release
3 years 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

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.4.1

3 years ago

0.3.2

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.3.4

3 years ago

0.4.2

3 years ago

0.3.3

3 years ago

0.2.0

4 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago