counter-upper
v1.0.0
Published
Pretty functional timer function.
Downloads
1
Readme
counter-upper
Pretty functional timer function. Dependency-free
1. Installation
$ npm i counter-upper
2. Usage
2.1. Start and stop, log ticks and tocks to console
const timer = require ('counter-upper')
const target = {
output: (msg) => {
console.log(msg)
}
}
let t = timer(target, () => console.log("It begins")).tick((target, ticks) => console.log(`tick ${ticks}`)).tock((target, tocks) => console.log("tock"))
setTimeout(() => {t.stop(()=>console.log("Enough!"))}, 5550)
2.2. Implementing promise
const timer = require("counter-upper")
let ticks = 0,
tocks = 0
const promise = new Promise((resolve, rejects) => {
let t = timer().tick(() => ticks += 1).tock(() => tocks += 1)
setTimeout(() => {
t.stop(()=>{
resolve('done')
})
}, 5550)
})
promise.then((status) =>
console.log(ticks, tocks, status))