Open gridagribnoy opened 3 months ago
See workers in action: https://stackblitz.com/edit/p-queue-workers?file=start.ts This code is not for production, but as an example it needs to be reworked.
I also suggest storing information in the queue not only in functions but also in the payload. For example, queue.add('https://...') and the worker itself decides how to process this information, this makes it possible to easily view the queue, serialize/deserialize it, for example for storing in the db. In general, you can write anything to the queue, be it a function, be it any data in a free form and structure. And the worker will decide how to process it.
I suggest adding pools and workers for them, possibly a separate library. This can be useful, for example, when you need to complete tasks in different ways; for this, separate workers are needed. Or, for example, there are tasks to get information from the API, but there is a limit, we can add another worker with a separate API key.
I already made a fork and tried to implement workers, it works. but it seems to me it is better to rewrite everything as a separate library.
Some ideas: