An advanced promise queue management library for JavaScript. This library is designed to handle the concurrency of any asynchronous tasks encapsulated in promises, providing optional debouncing to manage the flow of promise execution.
Simply download and include with a script tag, Queue
will be registered as a global variable.
<script src="../lib/queue.global.js"></script>
<script>
const queue = new Queue({ concurrency: 3, delay: 200 });
const asyncTask = function () {
return new Promise((resolve) => setTimeout(() => resolve("Task Complete"), 1000));
};
queue.add(asyncTask);
const asyncWithAbort = () => {
let timer;
const promise = new Promise((resolve) => {
timer = setTimeout(() => resolve("Another Task Complete"), 500);
});
const abortFunc = () => {
clearTimeout(timer);
console.log('Task was aborted');
};
return [promise, abortFunc]
}
queue.add(asyncWithAbort);
</script>
unpkg
<script src="https://unpkg.com/@nextgis/queue"></script>
jsdelivr
<script src="https://cdn.jsdelivr.net/npm/@nextgis/queue"></script>
We recommend linking to a specific version number /queue@[version]
npm install @nextgis/queue
import Queue from '@nextgis/queue';
const queue = new Queue({ concurrency: 2, delay: 100 });
const abortController = new AbortController();
queue.add(
() =>
fetch('https://api.example.com/data', {
signal: abortController.signal,
}),
abortController.abort,
);
// Demonstrating the abort function
setTimeout(() => {
queue.abort();
}, 100);
Check out the API Documentation
Need to fix a bug or add a feature to @nextgis/cache
? We provide custom development and support for this software. Contact us to discuss options!