1.0.1 • Published 3 years ago
concurrent-delay v1.0.1
concurrent-delay
A class that provides a way to delay a task
Installation
via npm:
$ npm install concurrent-delayvia yarn:
$ yarn add concurrent-delayExample
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:NumberNumber of milliseconds delayttl:NumberTime of seconds expireskey:StringKey can be consumed by IP address, user ID, authorisation token, API route or any other string.