auto-interval

    1.0.3 • Public • Published

    setAutoInterval

    setAutoInterval (auto-interval) is a newer ECMAScript setInterval implementation which balances cumulative timing errors.

    Example with setInterval

    var intervalID = setInterval(
      () => console.log("The Date.now() is ", Date.now()),
      100
    );
    setTimeout(clearInterval, 5000, intervalID); // Finish after 5s

    Example with setAutoInterval

    const { setAutoInterval } = require("auto-interval");
    var clearAutoInterval = setAutoInterval(
      () => console.log("The Date.now() is ", Date.now()),
      100
    );
    setTimeout(clearAutoInterval, 5000); // Finish after 5s

    What's the difference?

    Comparison of gap between ETA (Expected Time) and Actual Run Time in setInterval() and setAutoInterval().

    Demo

    Time Table for setInterval()

    Demo

    Time Table for setAutoInterval()

    Demo

    Advantages

    • Same function signature as setInterval()
    • Ultra-lightweight
    • Minimum code adaptation

    Demos and Tools

    Demonstration is here.

    Demo

    Demo

    License

    Copyright (C) 2020 Lautaro Capella (twitter: @PkuyApp).

    Install

    npm i auto-interval

    DownloadsWeekly Downloads

    6

    Version

    1.0.3

    License

    Apache License 2.0

    Unpacked Size

    15.1 kB

    Total Files

    5

    Last publish

    Collaborators

    • cape-