utilizes.interval
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

interval

This function is like native setInterval, except its stopped when the given handler returns true or an error is accrue

Usage: interval(handler: (...args) => boolean, timeout?: number, ...args): number

import { interval } from 'utilizes.interval'

let counter = 0

interval(()=> ++counter === 5)
// stopped when the counter incremented to 5
// or you can stop it manually like you stop native setInterval function ->
const handle = interval(()=> {

    ++counter

    if(counter === 5) clearInterval(handle)

})

// note: the interval is stopped when error is accrue ->
interval(()=>{
    throw new Error()
})
// log error to the console once and the interval no longer exist
// you can stop this behavior by using trycatch ->
interval(()=>{
    try{
        throw new Error()
    }catch(e){
        console.error(e)
    }
})
// this will not stop the interval process

This module exported from utilizes project.

Package Sidebar

Install

npm i utilizes.interval

Weekly Downloads

1

Version

1.2.3

License

MIT

Unpacked Size

54.3 kB

Total Files

5

Last publish

Collaborators

  • natqe3