3.0.0-alpha.13 • Published 8 months ago

@nextgis/queue v3.0.0-alpha.13

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Cache

size version

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.

  • Limit the number of concurrent promises.
  • Optional debouncing to manage the timing of promise execution.
  • Ability to abort queued promises.
  • Efficient and orderly management of asynchronous operations.

Installation

In Browser

Include assets

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>

CDN

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]

In Node.js

npm install @nextgis/queue

Usage

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

Commercial support

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!

http://nextgis.com

3.0.0-alpha.13

8 months ago

3.0.0-alpha.5

9 months ago

2.3.0

1 year ago

3.0.0-alpha.1

11 months ago

2.5.0

11 months ago

3.0.0-alpha.0

11 months ago

3.0.0-alpha.3

11 months ago

2.2.1

1 year ago

2.1.0

1 year ago