concurrent-delay
v1.0.1
Published
A class that provides a way to delay a task
Downloads
1
Maintainers
Readme
concurrent-delay
A class that provides a way to delay a task
Installation
via npm:
$ npm install concurrent-delay
via yarn:
$ yarn add concurrent-delay
Example
import { DelayRequest } from 'concurrent-delay';
// Use redis
const cDelay = new DelayRequest({ host: 'localhost', port: 6379 });
// Job delay every 2 seconds takes effect for 60 seconds
app.get('/task', async (req, res) => {
await cDelay.delay({ ms: 2000, ttl: 60, key: 'abc' });
res.send('ok');
});
API options
new DelayRequest(options)
Redis store for concurrent-delay, visit ioredis configuration
delay(options)
ms
:Number
Number of milliseconds delayttl
:Number
Time of seconds expireskey
:String
Key can be consumed by IP address, user ID, authorisation token, API route or any other string.