Почему я не могу просто использовать это.next () ? Почему я должен обрабатывать его в следующем цикле событий? < /P>
export class TaskQueue {
constructor (concurrency) {
this.concurrency = concurrency
this.running = 0
this.queue = []
}
pushTask (task) {
this.queue.push(task)
process.nextTick(this.next.bind(this)) // this is to avoid Zalgo situation
return this
}
next () {
while (this.running < this.concurrency && this.queue.length) {
const task = this.queue.shift()
task(() => {
this.running--
process.nextTick(this.next.bind(this)) // why is this used?
})
this.running++
}
}
}
< /code>
Я удалил процесс.nexttick (), и он все еще работал совершенно хорошо. Так что я не понимаю смысла этого. Может ли кто -нибудь объяснить в каких ситуациях, что мои рассуждения не пройдут?
Подробнее здесь: https://stackoverflow.com/questions/794 ... ementation