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

set-timeout-by-id

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-timeout-by-id

A simple package to set and clear a timeout by id instead of using variables.

0.1.3
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

What is this?

This is a timeout implementation that allows you to set a timeout and then clear it using keys instead of the timeout variable reference.
This is useful when you have to clear a timeout from a different scope than the one where it was set.

How To Install?

npm install set-timeout-by-id

How To Use?

import { setTimeoutById, clearTimeoutById } from 'set-timeout-by-id';

const timeoutId = setTimeoutById(() => {
  console.log('Hello World!');
}, 1000, 'myTimeout'); // This will set a timeout with the id 'myTimeout'

// Meanwhile, in another file...
clearTimeoutById('myTimeout'); // This will clear the timeout

How does it work under the hood?

This library uses a Map to store the timeout references, leveraging the singleton pattern.
When you set a timeout, it will be stored in the Map with the given id as key.
When you clear a timeout, it will be removed from the Map and cleared using the reference stored in the Map.

How to run tests?

npm test

Contributing

If you want to contribute to this project, please open an issue or a pull request.
I will be happy to review it and merge it if it's useful.
Please, remember to follow the Conventional Commits standard.

Keywords

npm

FAQs

Package last updated on 27 Dec 2023

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