* Add a new item to the queue * * @param bucket bucket name * @param item function that will run later * @param options
(bucket: string, item: Function, options: DelayQueueOptions)
| 23 | * @param options |
| 24 | */ |
| 25 | push(bucket: string, item: Function, options: DelayQueueOptions): void { |
| 26 | const callback = options.callback || process.nextTick; |
| 27 | if (!this.queues[bucket]) { |
| 28 | this.queues[bucket] = new Deque(); |
| 29 | } |
| 30 | |
| 31 | const queue = this.queues[bucket]; |
| 32 | queue.push(item); |
| 33 | |
| 34 | if (!this.timeouts[bucket]) { |
| 35 | this.timeouts[bucket] = setTimeout(() => { |
| 36 | callback(() => { |
| 37 | this.timeouts[bucket] = null; |
| 38 | this.execute(bucket); |
| 39 | }); |
| 40 | }, options.timeout); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | private execute(bucket: string): void { |
| 45 | const queue = this.queues[bucket]; |
no test coverage detected