https://github.com/stoqey/timeout-manager
View and Manage NodeJS's timeout and interval as collections
https://github.com/stoqey/timeout-manager
interval settimeout timeout-timeoutcollection
Last synced: 6 months ago
JSON representation
View and Manage NodeJS's timeout and interval as collections
- Host: GitHub
- URL: https://github.com/stoqey/timeout-manager
- Owner: stoqey
- License: mit
- Created: 2020-05-17T20:46:14.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-26T14:32:10.000Z (over 5 years ago)
- Last Synced: 2025-09-05T19:11:52.405Z (7 months ago)
- Topics: interval, settimeout, timeout-timeoutcollection
- Language: TypeScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# timeout-manager
View and Manage NodeJS's timeout and interval as collections
# Installation
```$ yarn add timeout-manager```
# Usage
```ts
import { timeoutCollection } from '@stoqey/timer-manager';
// creating a timeout
const firstTimeoutID = setTimeout(function () {
console.log('First timeout, after 5 seconds');
}, 5000);
const secondTimeoutID = setTimeout(function () {
console.log(timeoutCollection.getAll().map(id => id.uuid));
console.log('second timeout, after 8 seconds');
}, 8000);
console.log(timeoutCollection.get(firstTimeoutID)); //timeout object
// Removing the first timeout
timeoutCollection.remove(firstTimeoutID);
console.log(timeoutCollection.getAll().map(id => id.uuid));
// Other methods
timeoutCollection.getScheduled(); //Returns an array of timeout objects that have not yet executed
timeoutCollection.getCompleted(); //Returns an array of timeout objects that have been executed
timeoutCollection.getAll(); //Returns an array of timeout objects
timeoutCollection.removeAll();
```
# Why?
NodeJS will not expose us a simple object or array to view and manage all of our current time-events.
This library exposes the timeouts and intervals in your current node app. In addition, it makes
it possible to manage those time-events on `runtime`.