A utility class for managing timeouts created by setTimeout
.
You can install the package using npm:
npm install set-timeout-manager
// ES6 import
import SetTimeout from 'set-timeout-manager';
// (or) CommonJS require
const SetTimeout = require('set-timeout-manager');
const mockFn = () => 'set-timeout-manager';
// --- (start + clear) ---
SetTimeout.start(mockFn, 1000, 'basic-example');
SetTimeout.clear('basic-example');
// --- (start + clearAll) ---
SetTimeout.start(mockFn, 1000, 'timeout-one');
SetTimeout.start(mockFn, 1500, 'timeout-two');
SetTimeout.start(mockFn, 2000, 'timeout-three');
SetTimeout.clearAll();
// --- (start + listAll) ---
SetTimeout.start(mockFn, 1000, 'timeout-one');
SetTimeout.start(mockFn, 1500, 'timeout-two');
SetTimeout.listAll(); // => ['timeout-one', 'timeout-two']
SetTimeout.clear('timeout-one');
SetTimeout.listAll(); // => ['timeout-two']
The main class exported by the package.
Starts a new timeout that calls the specified function at the specified delay.
fn
(required): The function to call.delay
(required): The delay (in milliseconds) at which to call the function.key
(required): A unique string identifier for the timeout.
Stops the timeout with the specified key.
key
(required): The string identifier for the timeout to stop.
Stops all timeouts managed by this utility.
Gets an array of all keys currently being used to manage timeouts.
This package is released under the MIT License.