Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    timers-refpublic

    timers-ref travis npm downloads

    setTimeout and setInterval with unref and ref like in node.js

    Please only use this in the browser, not in node.

    install

    npm install timers-ref

    usage

    var timers = require('timers-ref')
     
    timers.setTimeout(function () {
      console.log('hi')
    }, 100)
     
    timers.setInterval(function () {
      console.log('hi')
    }, 100)
     
    var timeout = timers.setTimeout(function () {}, 100)
    timers.clearTimeout(timeout)
     
    var interval = timers.setInterval(function () {}, 100)
    timers.clearInterval(interval)

    If you want to listen to process.on('exit') to know when there are no setTimeout or setInterval timers in the event queue, do this:

    timers.setupProcess()
     
    process.once('exit', function (code) {
      console.log('all done')
    })

    Note one important difference: This won't emit process.on('exit') if no setTimeouts or setIntervals are called. Needs at least one call to get things going.

    license

    MIT. Copyright (c) Feross Aboukhadijeh.

    install

    npm i timers-ref

    Downloadslast 7 days

    1

    version

    0.1.3

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar