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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.2.30latest

Version History

VersionDownloads (Last 7 Days)Published
1.2.30
1.2.20
1.2.10
1.2.00
1.1.100
1.1.90
1.1.80
1.1.60
1.1.40
1.1.30
1.1.20
1.1.10
1.1.00
1.0.110
1.0.60
1.0.40
1.0.30
1.0.20
1.0.10

Package Sidebar

Install

npm i utilizes.interval

Weekly Downloads

0

Version

1.2.3

License

MIT

Unpacked Size

54.3 kB

Total Files

5

Last publish

Collaborators

  • natqe3