2.0.1 • Published 4 years ago

valaxy-timer v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Dependency Status devDependency Status

Timer is tiny async utility, to seek for a more powerful async tool, see async

Introduction

Timer controls a task to execute repeatedly.
Module src/timer is CommonJS package

Example

import Timer = require('timer')

// instantiate a Timer
let timer = new Timer({
    interval: 1000, // how long between two runnings of tasks, default is 1000ms
    task: function (next) {
        console.log('task execute')
        next() // you must call next() to trigger next task running
    }
})

// start the timer, the first task will execute after `interval`
// start a started-timer will do nothing
timer.start()

// stop the timer
// stop a stopped-timer will do nothing
timer.stop()

// immediate execute task no matter how long until next task
// if timer has not started, start first and then execute task immediately
timer.immediate()