Async recursive timers
npm install often --save
var often = require('often')
- Get an
often
instance withfn
as recursion function - All methods are chainable
Set interval to wait between recursions
Start recursing after optional ms delay
Immediately stop recursing
Immediately stop recursing and void instance
Replace the recursion function
Clear active timer
Nullify properties
Initialize instance
._function
:fn
|null._recur
: boolean|null._timer
: integer|null._trial
: integer|null._wait
:ms
|null
var often = require('often')
often(function() {
console.log(new Date)
if ('someCondition') {
this.done()
}
}).wait(1000).start()
var often = require('often')
often(function() {
console.info(this)
if (this._trial === 3) {
this.stop()
console.warn(this)
}
}).start(1000).wait(200)
var often = require('often')
often(function() {
if ('Not Ready Yet') {
this.wait(1000 + this._wait)
console.info('Slowing down')
} else {
console.info('Ready!')
}
}).start()
var often = require('often')
var energy = require('energy')
var emitter = energy()
var heartbeat = often(function() {
emitter.emit('heartbeat')
}).wait(1000).start()
emitter.on('heartbeat', function() {
console.log('I run every second')
})
git clone https://github.com/ryanve/often.git
cd often
npm install
npm test
MIT