2.1.0 • Published 2 years ago

@iocmd/hold-up v2.1.0

Weekly downloads
737
License
MIT
Repository
github
Last release
2 years ago

Hold Up License NPM version Build Status Coverage Status

hold up is setInterval with promises, counter and error handling. It runs a function and if it throws run it again with interval (defaults to 1 second) counter times (defaults to 5). If it fails, promise throws, if successed resolves.

Install

npm i @iocmd/hold-up --save

API

holdUp(fn, options)

holdUp(fn, args, options)

  • fn - function
  • args - array of arguments
  • options - options may contain:
    • log
    • count
    • time
const holdUp = require('hold-up');
const fn = async (a = 'hello') => {
    throw Error(a);
};

await holdUp(fn);

// reject in a 5 seconds
// [Error: hello]

// with arguments
await holdUp([fn, 'world']);

// reject in a 5 seconds
//[Error: hello]

// when you need to override options,
await holdUp([fn, 'hello'], {
    count: 5,       // default
    time: 1000,     // default
    log: () => {},  // default
});

Related

  • currify - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments.

  • fullstore - functional variables.

  • wraptile - translate the evaluation of a function that takes multiple arguments into evaluating a sequence of 2 functions, each with a any count of arguments.

License

MIT

2.1.0

2 years ago

2.0.0

2 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago