better-timer
TypeScript icon, indicating that this package has built-in type declarations

2.0.4 • Public • Published

npm

better-timer

Timer class that supports both promises and multiple callbacks.

Installation

Add the script to your project through a package manager:

$ npm i better-timer

or

$ yarn add better-timer

Alternatively you can also import the script found in the releases section on GitHub directly. If you choose this option you won't need to use imports going forward - everything will all be available to you automatically.

<script src="better-timer.min.js"></script>

Or include through a public CDN:

<script src="https://unpkg.com/better-timer@2/dist/better-timer.min.js"></script>

General Api

  new Timer(duration, ...callbacks)

Code example

  import Timer from 'better-timer';
  // OR
  const Timer = require('better-timer');

  // Duration in Milliseconds
  const duration = 1000;

  const timer = new Timer(duration, () => {
    // Callbacks are optional
    console.log('Callback executed!');
  });

  // Get promise and add "then" block
  timer.promise.then(() => {
    console.log('Promise resolved!');
  });

  // Pause timer
  timer.pause();

  // Resume timer
  timer.resume();

  // Cancel timer
  timer.cancel();

Package Sidebar

Install

npm i better-timer

Weekly Downloads

0

Version

2.0.4

License

MIT

Unpacked Size

19.7 kB

Total Files

15

Last publish

Collaborators

  • wotschofsky