Package Exports
- zeno-queue
- zeno-queue/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (zeno-queue) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ZenoQueue
A minimal, high-performance Promise-based queue.
Features
- ~40% faster than array-based queues
- Zero dependencies
- Tiny (398 bytes)
- Simple API
- Sequential Promise execution
- AbortController cancellation
Installation
npm install zeno-queue
or
import { ZenoQueue } from 'https://unpkg.com/zeno-queue/index.js';
Usage
import { ZenoQueue } from 'zeno-queue';
const queue = new ZenoQueue();
// Queue an operation
queue(() => console.log('First'));
// Queue an async operation
queue(async () => {
await someAsyncWork();
console.log('Second');
});
// Cancel an operation
const task = queue(processData);
task.abort();
Note, tasks can only be aborted before they have started. If you need the ability to cancel a long running task, you should use an AbortController signal in your callback.
const controller = new AbortController();
queue(() => {
for (let i=0; i<100000; i++) {
if (controller.signal.aborted) {
return;
}
// your operation goes here
}
});
controller.abort();
Performance
Tested with 100,000 operations:
ZenoQueue: 680.84ms
Array Queue: 1127.90ms
Why ZenoQueue?
ZenoQueue processes operations sequentially with O(1) complexity by chaining Promises rather than using traditional O(n) Array operations.