(
maxTasksPerSecond = 4,
maxSimultaneousTasks = 8,
maxQueueLength = 20
)
| 1 | export default class TaskQueue { |
| 2 | constructor( |
| 3 | maxTasksPerSecond = 4, |
| 4 | maxSimultaneousTasks = 8, |
| 5 | maxQueueLength = 20 |
| 6 | ) { |
| 7 | this.maxTasksPerSecond = maxTasksPerSecond; |
| 8 | this.maxQueueLength = maxQueueLength; |
| 9 | this.maxSimultaneousTasks = maxSimultaneousTasks; |
| 10 | this.queue = []; |
| 11 | this.processing = false; |
| 12 | this.lastProcessTime = 0; |
| 13 | this.taskCount = 0; |
| 14 | this.tasksWaiting = 0; |
| 15 | } |
| 16 | |
| 17 | async enqueue(taskFunction, that = this, ...args) { |
| 18 | return new Promise((resolve, reject) => { |
nothing calls this directly
no outgoing calls
no test coverage detected