sindresorhus / p-queue

Promise queue with concurrency control
MIT License
3.45k stars 185 forks source link

CustomQueue doesn't work? #122

Closed nguyentoanit closed 3 years ago

nguyentoanit commented 3 years ago

Hi,

I am trying CustomQueue in p-queue libs. But got an error need your help:

Sample:

    class CustomQueue {
      private readonly _queue: RunFunction[] = []
      constructor() {
        this._queue = [];
      }
      enqueue(run: RunFunction, options?: Partial<PriorityQueueOptions>): void {
        this._queue.push(run);
      }
      dequeue(): RunFunction | undefined {
        return this._queue.shift();
      }
      get size(): number {
        return this._queue.length;
      }
      filter(options: Readonly<Partial<PriorityQueueOptions>>): RunFunction[] {
        return this._queue;
      }
    }
    const queue = new PQueue({
      autoStart: false,
      queueClass: () => new CustomQueue()
    })

Error message:

Type '() => CustomQueue' is not assignable to type 'new () => PriorityQueue'.
  Type '() => CustomQueue' provides no match for the signature 'new (): PriorityQueue'.

Something is wrong? 🤔

Docs: https://github.com/sindresorhus/p-queue#custom-queueclass

sindresorhus commented 3 years ago

You need to pass the class, not the instance.