sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.39k stars 182 forks source link

#isIntervalPaused maybe useless #166

Open KK-AI-LL opened 2 years ago

KK-AI-LL commented 2 years ago

I'm reading source code to figure out how this lib works and I think #isIntervalPaused maybe useless and brings lots of related useless code.

if (!this.#isPaused) {
    const canInitializeInterval = !this.#isIntervalPaused;  // THIS IS USELESS , REMOVE IT
    if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
        const job = this.#queue.dequeue();
        if (!job) {
            return false;
        }

        this.emit('active');
        job();

        if (canInitializeInterval) {  // CHANGE 'canInitializeInterval' TO ‘this.#intervalId === undefined’ and remove any code no longer used
            this.#initializeIntervalIfNeeded();
        }

        return true;
    }
}

As shown above, when code changes, all tests passed.

I found that these codes were introduced in this pr to enable p-queue the ability to throttle the queue, but #isIntervalPaused seems to be useless in this case, for that when I remove it from code as shown above, all test still passed, anyone can help me figure it out? Thanks.