Noodles Practicing Medicine

    @hasezoey/interval-promise-ts
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.0 • Public • Published

    Interval Promise re-write to TS

    its a rewrite to TS Original by Andy Fleming

    using my(hasezoey) TS config & lint options

    The Following is from the original Readme

    Overview

    This library provides a simple mechanism for running a promise with a given amount of time between executions.

    Standard Javascript » setInterval()

    traditional interval

    interval-promise » interval()

    interval promise

    Usage

    Simple example using async-await

    const interval = require('interval-promise')
    
    // Run a function 10 times with 1 second between each iteration
    const id = interval.interval(async () => {
        await someOtherPromiseReturningFunction()
        await another()
    }, 1000, {iterations: 10})
    
    // clear it
    await clearInterval(id);
    import { interval, clearInterval } from "interval-promise";
    
    // Run a function 10 times with 1 second between each iteration
    const id: string = interval(async () => {
        await someOtherPromiseReturningFunction()
        await another()
    }, 1000, {iterations: 10})
    
    // clear it
    await clearInterval(id);

    API

    interval(cb: function, intervalLength: number | Infinity, options: IOptions): Promise<void>;

    Arguments

    Argument Attritubes Description
    cb function Required
    Function to execute for each interval. MUST return a promise.

    Two arguments are passed to this function.
    • iterationNumber number — The iteration number (starting at 0)
    • stop function — used to "stop" (skipping all remaining iterations)
    intervalLength number | function Required
    Length in ms to wait between iterations. Should be (or return) a non-negative integer.

    If a function is used, one parameter iterationNumber (starting at 1) is passed.
    options object Optional settings (detailed below).
    options.iterations number Default: Infinity
    The number of times to execute the function. Must be Infinity or an integer greater than 0.
    (note: counting from 0)
    options.stopOnError boolean Default: true
    If true, no subsequent calls will be made. The promise returned by interval() will be rejected and pass through the error thrown.
    clearInterval(id: string): Promise<void>;

    Arguments

    Argument Attritubes Description
    id string Required
    ID returned by an interval

    More on "intervalLength" as a function

    It will be called with "0" once (the initial call for the first run), and after that "Infinity" if it is set to run Infinite, otherwise a normal number

    Project Values

    • Approachability — Basic usage should be concise and readable.
    • Debuggability — Error feedback should be helpful and error handling options should be flexible.
    • Stability — Functionality should be well-tested and reliable.

    Keywords

    none

    Install

    npm i @hasezoey/interval-promise-ts

    DownloadsWeekly Downloads

    1

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    14.6 kB

    Total Files

    5

    Last publish

    Collaborators

    • hasezoey