This is non-blocking and very easy in usage queue (or any data) handler for Node.js applications. Provide an options object which should contains next properties:
- taskHandler - function which will handle your tasks;
- successCallback - function which takes returned by taskHandler data as an argument;
- errorCallback - function which will be called when taskHandler fails;
- eventEmitTimeoutValue - positive integer, milliseconds between ticks;
TaskManager instance has one method:
- addTask(), which enqueues provided task;
This is an example of usage (You can run this code with esm module for supporting import: node -r esm ...):
; const taskManager = { console; if task_id && task_id % 2 throw 'Some test error message' return task; } console console eventEmitTimeoutValue: 2000; for let i = 0; i < 10; i++ ;
That's all, thanks for attention and good luck !