counter-upper

1.0.0 • Public • Published

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))

Readme

Keywords

none

Package Sidebar

Install

npm i counter-upper

Weekly Downloads

8

Version

1.0.0

License

ISC

Unpacked Size

2.99 kB

Total Files

5

Last publish

Collaborators

  • r_md-p