repeated-calls

    1.3.0 • Public • Published

    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.

    Keywords

    Install

    npm i repeated-calls

    DownloadsWeekly Downloads

    16

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    9.91 kB

    Total Files

    6

    Last publish

    Collaborators

    • krivega