Socket
Socket
Sign inDemoInstall

sgb004-timer

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sgb004-timer

Timer


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Timer

This is a class that allows you to create a simple timer in JavaScript. You can use this class to execute a callback function periodically after a specified time interval.

Installation

To install the Timer you can use npm:

npm i sgb004-timer

Usage

To use it, simply create a new Timer instance passing in the callback function, interval in milliseconds, and optionally an initial delay:

const timer = new Timer(() => { console.log('¡Hola!'); }, 1000, 5000);

This will execute the callback function every second, after an initial 5 seconds delay.

Then to start the timer, call the start() method:

timer.start();

And to stop it, use stop():

timer.stop();

You can also restart the timer with reset():

timer.reset();

API

Constructor

  • callback - Function to execute on each interval.
  • time - (Optional) Interval in milliseconds.
  • delay - (Optional) Initial delay in milliseconds before starting.

Methods

  • start() - Starts the timer execution.
  • stop() - Stops the timer.
  • reset() - Restarts the timer.

Author

sgb004

License

MIT

Keywords

FAQs

Last updated on 10 Oct 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc