You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

setinterval

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

setinterval

[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]

0.2.0
Source
npmnpm
Version published
Maintainers
1
Created
Source

setinterval

NPM version npm download

More reasonable setInterval for async task.

Install

$ npm i setinterval

Example

  const Timer = require('setinterval');
  const t = new Timer(function*() {
    const user = yield db.User.get(id);
    console.log(user);
  }, 1000);

  // start timer
  t.setInterval();

  // xxxx
  t.clearInterval();

API

  • setInterval(fn, period)

fn should be a Promise, a generator function or a thunk.

  • clearInterval()

cancel timer.

Events

  • tick

Triggered each time fn is finished, whenever a error is thrown. You can cancel the timer in this event. A count parameter is passed in the event handler which stands for how many times fn has been called.

timer.on('tick', count => {
  timer.clearInterval();
});
  • error

Triggered when error thrown from fn.

timer.on('error', e => {
  logger.info(e.stack);
});

License

MIT

Keywords

setInterval

FAQs

Package last updated on 20 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts