Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promised-timer

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promised-timer

Promisified Javascript Timer

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

promised-timer

Promisified Javascript Timer

import Timer from 'promised-timer';

let aTimer = Timer.Seconds(5);

startButton.onClick(() => {
  aTimer.start()
    .then(() => doSomething())
    .catch((e) => log('Exception in doSomething', e))
});

cancelButton.onClick(() => aTimer.cancel());
rightNowButton.onClick(() => aTimer.trigger());

A timer can be started multiple times, canceled, paused and rewound. Paused timer can be resumed to continue up to initial time.

Static Timer.delay method serves well for simpler cases.

Stopwatch

Attach multiple promises to timeline

import { Stopwatch } from 'promised-timer';

const w = new Stopwatch();
w.at(300).then(elapsed => {
      elapsed == 300
  });

w.at(1000).then(elapsed => {
      elapsed == 1000
  });

w.start().then(() => "stopwatch stopped", () => "stopwatch cancelled");

Timer.delay(3000, w.stop());

The stopwatch can be paused and resumed.

Swapping Promise implementation

By default Timer assumes native Promise or polyfill but any Promise implementation can be used by setting Timer.Promise property.


Development Requirements

Typescipt 2.0+

Commands
  • npm run build - build a version
  • npm run clean - removes dist and build folder
  • npm start - starts local dev server at http://localhost:8006/
  • npm run lint - lint
  • npm test - runs karma tests
  • npm run test:watch - watch tests

Keywords

FAQs

Package last updated on 09 Dec 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc