Registry / devops / fetch-scheduler

fetch-scheduler

JSON →
library0.4.0jsnpmunverified

A lightweight library for scheduling and throttling large numbers of fetch requests in the browser or Node.js. Version 0.4.0 allows you to limit concurrent fetch requests, queue excess requests, and individually cancel or remove requests. The package ships with ESM and UMD bundles, works with both import and script tag usage, and includes TypeScript definitions. Compared to Promise pools or manual throttling, it provides a dedicated `createFetch` method that returns a cancelable promise and offers built-in statistics. It has a minimal API surface with only one main class, making it easy to integrate into data-heavy applications such as tile map loading or API batch processing.

npm install fetch-scheduler
INSTALL
IMPORT
SIG · FETCH-SCHEDULER
F
fetch-scheduler
devopsjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FetchScheduler
import { FetchScheduler } from 'fetch-scheduler';
import FetchScheduler from 'fetch-scheduler';
Default export is not available; always use named import.
FetchScheduler (CDN)
const FetchScheduler = fs.FetchScheduler;
const fetchScheduler = new FetchScheduler();
When using the UMD/global script, the library is exposed as `fs` global, not `FetchScheduler` directly.
Type definition
import type { FetchScheduler as T } from 'fetch-scheduler';
import FetchScheduler from 'fetch-scheduler';
If you only need the type, use type import. The library ships TypeScript definitions, but the type is not exported as a separate type.

Demonstrates creating a FetchScheduler, queuing two concurrent fetch requests, and retrieving scheduler statistics.

import { FetchScheduler } from 'fetch-scheduler'; // Create a scheduler with max 3 concurrent requests const scheduler = new FetchScheduler({ requestCount: 3 }); // Create and queue fetch requests const url1 = 'https://api.example.com/data/1'; const url2 = 'https://api.example.com/data/2'; const promise1 = scheduler.createFetch(url1, { method: 'GET' }); const promise2 = scheduler.createFetch(url2, { method: 'GET' }); promise1.then(response => { if (!response.ok) throw new Error('Network error'); return response.json(); }).then(data => { console.log('Success:', data); }).catch(err => { console.error('Failed:', err); }); // Get statistics console.log(scheduler.getCurrentInfo()); // { pending: 0, running: 2, max: 3 }
Debug
Known issues
gotchaThe `createFetch` method returns a promise that also has `.cancel()` and `.remove()` methods. You cannot use `.cancel()` on the response from `.then()`; you must keep a reference to the original promise.
fix
Store the promise returned by `createFetch` directly: `const req = scheduler.createFetch(url, opts);` then use `req.cancel();`.
affects: >=0.0.0
gotchaWhen using the UMD/global build from a script tag, the library is available as `fs.FetchScheduler`, not `FetchScheduler` directly. Named exports are not available.
fix
Use: `const fs = window.fs; const scheduler = new fs.FetchScheduler({...});`
affects: >=0.0.0
gotchaThe `requestCount` option defaults to 6 if not provided, which may be too low for some use cases (e.g., browser typically allows 6 concurrent connections per domain). You may need to adjust based on environment.
fix
Explicitly set `requestCount` to a value appropriate for your environment (e.g., 10 for Node.js, 6 for browser).
affects: >=0.0.0
gotchaThe `createFetch` method's second argument is the standard `fetch` options object. However, if you pass a non-standard extension (like `signal` for AbortController), it may conflict with the internal promise cancellation.
fix
Do not pass `signal` in fetch options; use the promise's `.cancel()` method instead.
affects: >=0.0.0
Errors
Common errors & fixes
Uncaught TypeError: fetchScheduler.createFetch is not a function
Using default import instead of named import: `import FetchScheduler from 'fetch-scheduler'` but there is no default export.
fix
Use named import: `import { FetchScheduler } from 'fetch-scheduler';`
ReferenceError: FetchScheduler is not defined
Using the global script but trying to access `new FetchScheduler()` directly; the global is `fs`.
fix
Use `const FetchScheduler = window.fs.FetchScheduler;` or `const { FetchScheduler } = window.fs;`
TypeError: promise.cancel is not a function
Attempting to cancel the response promise (e.g., `scheduler.createFetch(...).then(...)`) instead of the original promise returned by `createFetch`.
fix
Store the promise: `const p = scheduler.createFetch(...); p.cancel();`
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
fetch-scheduler — npm install fetch-scheduler · libregistry