Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krivega/repeated-calls
Repeated calls to the function
https://github.com/krivega/repeated-calls
Last synced: 28 days ago
JSON representation
Repeated calls to the function
- Host: GitHub
- URL: https://github.com/krivega/repeated-calls
- Owner: Krivega
- License: mit
- Created: 2020-03-03T08:21:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-07T16:27:23.000Z (3 months ago)
- Last Synced: 2024-12-12T04:19:33.444Z (about 1 month ago)
- Language: TypeScript
- Size: 504 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# repeated-calls
Repeated calls to the function
[![npm](https://img.shields.io/npm/v/repeated-calls?style=flat-square)](https://www.npmjs.com/package/repeated-calls)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/repeated-calls?style=flat-square)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
```sh
npm install repeated-calls
```yarn
```sh
yarn add repeated-calls
```## Usage
```js
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
```js
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
```js
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
```sh
npm test
```## Maintainer
**Krivega Dmitriy**
- Website:
- Github: [@Krivega](https://github.com/Krivega)## Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/Krivega/repeated-calls/issues). You can also take a look at the [contributing guide](https://github.com/Krivega/repeated-calls/blob/master/CONTRIBUTING.md).## 📝 License
Copyright © 2020 [Krivega Dmitriy](https://github.com/Krivega).
This project is [MIT](https://github.com/Krivega/repeated-calls/blob/master/LICENSE) licensed.