2.3.0 • Published 8 months ago

repeated-calls v2.3.0

Weekly downloads
6
License
MIT
Repository
github
Last release
8 months ago

repeated-calls

Repeated calls to the function

npm npm bundle size

A stack of tasks that are executed one by one, but the result is taken from the last. Identical functions on the stack (check by reference) are executed only once.

Install

npm

npm install repeated-calls

yarn

yarn add repeated-calls

Usage

import repeatedCalls from 'repeated-calls';

const targetFunction = function innerTargetFunction() {
  innerTargetFunction.count = innerTargetFunction.count || 0;

  innerTargetFunction.count += 1;

  return innerTargetFunction.count;
};
const isComplete = (callCount) => callCount === 3;

return repeatedCalls({ targetFunction, isComplete }).then((callCount) => {
  console.log(callCount); // 3
});

Complete if the limit is reached

import repeatedCalls from 'repeated-calls';

const targetFunction = function innerTargetFunction() {
  innerTargetFunction.count = innerTargetFunction.count || 0;

  innerTargetFunction.count += 1;

  return innerTargetFunction.count;
};
const isComplete = (callCount) => callCount === 3;
const callLimit = 3;

return repeatedCalls({ targetFunction, isComplete, callLimit }).catch((error) => {
  console.log(error); // call limit (3) is reached
});

Use async targetFunction

import { repeatedCallsAsync } from 'repeated-calls';

const targetFunction = function innerTargetFunction() {
  innerTargetFunction.count = innerTargetFunction.count || 0;

  innerTargetFunction.count += 1;

  return Promise.resolve(innerTargetFunction.count);
};
const isComplete = (callCount) => callCount === 3;

return repeatedCalls({ targetFunction, isComplete }).then((callCount) => {
  console.log(callCount); // 3
});

Run tests

npm test

Maintainer

Krivega Dmitriy

Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.

📝 License

Copyright © 2020 Krivega Dmitriy. This project is MIT licensed.

2.3.0

8 months ago

2.2.1

12 months ago

2.2.0

12 months ago

2.1.0

12 months ago

2.0.1

1 year ago

1.3.3

1 year ago

2.0.0

1 year ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.4

4 years ago

0.0.3

5 years ago

0.0.2

5 years ago