并发限制k版本,牛客咋不让贴代码了?? class Scheduler { constructor(limit) { this.queue = []; this.limit = limit; this.currentTaskCount = 0; } add(fn) { return new Promise((resolve, reject) => { this.queue.push([fn, resolve]); this.exc(); }) } exc() { if (this.currentTaskCount < this.limit && this.queue.length) { const [fn, resolve] = this.queue.shift(); this.currentTaskCount++; Promise.resolve(fn()).then((result) => { resolve(result); this.currentTaskCount--; this.exc(); }) } } }