2.3.0 • Published 1 year ago
repeated-calls v2.3.0
repeated-calls
Repeated calls to the function
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-callsyarn
yarn add repeated-callsUsage
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 testMaintainer
Krivega Dmitriy
- Website: https://krivega.com
- Github: @Krivega
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.