delayed-call v1.0.15
delayed-call
For making delayed function calls
Pass any number of arguments to the delayed function. Delayed calls can be cleared between creation and execution. Clear single delayed call or all at once.
Install
$ npm install --save delayed-call
API
create(ms, fn, ...args)
Create a delayed call
Parameters
ms
: number
Delay in milliseconds.
fn
: function
The function to be called after the delay.
...args
: *
Optional. Any number of arguments supplied to the delayed function.
Returns
id
: number
The id of the delayed call.
Usage
const delayedCall = require('delayed-call');
delayedCall.create(500, () => {
console.log('I am delayed');
});
// Prints "I am delayed" after 500 ms.
delayedCall.create(1000, (arg1, arg2) => {
console.log(arg1 + ' ' + arg2);
}, 'Hello', 'world!');
// Prints "Hello world!" after 1000 ms.
clearById(id)
Clear a single created delayed call
Parameters
id
: number
The id of the delayed call to be cleared.
Usage
const delayId = delayedCall.create(500, () => {
console.log('Hello!');
});
delayedCall.clearById(delayId);
// Prints nothing.
// The delayed call is cleared before execution.
clearAll()
Clear all created delayed calls
Usage
delayedCall.create(500, () => {
console.log('Hello');
});
delayedCall.create(1000, () => {
console.log('world!');
});
delayedCall.clearAll();
// Prints nothing.
// The delayed calls are cleared before execution.
License
MIT © Finn-Olav Myrvold
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago