{"id":47650,"library":"fetch-scheduler","title":"fetch-scheduler","description":"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.","status":"active","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/deyihu/fetch-scheduler","tags":["javascript"],"install":[{"cmd":"npm install fetch-scheduler","lang":"bash","label":"npm"},{"cmd":"yarn add fetch-scheduler","lang":"bash","label":"yarn"},{"cmd":"pnpm add fetch-scheduler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is not available; always use named import.","wrong":"import FetchScheduler from 'fetch-scheduler';","symbol":"FetchScheduler","correct":"import { FetchScheduler } from 'fetch-scheduler';"},{"note":"When using the UMD/global script, the library is exposed as `fs` global, not `FetchScheduler` directly.","wrong":"const fetchScheduler = new FetchScheduler();","symbol":"FetchScheduler (CDN)","correct":"const FetchScheduler = fs.FetchScheduler;"},{"note":"If you only need the type, use type import. The library ships TypeScript definitions, but the type is not exported as a separate type.","wrong":"import FetchScheduler from 'fetch-scheduler';","symbol":"Type definition","correct":"import type { FetchScheduler as T } from 'fetch-scheduler';"}],"quickstart":{"code":"import { FetchScheduler } from 'fetch-scheduler';\n\n// Create a scheduler with max 3 concurrent requests\nconst scheduler = new FetchScheduler({ requestCount: 3 });\n\n// Create and queue fetch requests\nconst url1 = 'https://api.example.com/data/1';\nconst url2 = 'https://api.example.com/data/2';\nconst promise1 = scheduler.createFetch(url1, { method: 'GET' });\nconst promise2 = scheduler.createFetch(url2, { method: 'GET' });\n\npromise1.then(response => {\n  if (!response.ok) throw new Error('Network error');\n  return response.json();\n}).then(data => {\n  console.log('Success:', data);\n}).catch(err => {\n  console.error('Failed:', err);\n});\n\n// Get statistics\nconsole.log(scheduler.getCurrentInfo()); // { pending: 0, running: 2, max: 3 }","lang":"typescript","description":"Demonstrates creating a FetchScheduler, queuing two concurrent fetch requests, and retrieving scheduler statistics."},"warnings":[{"fix":"Store the promise returned by `createFetch` directly: `const req = scheduler.createFetch(url, opts);` then use `req.cancel();`.","message":"The `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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use: `const fs = window.fs; const scheduler = new fs.FetchScheduler({...});`","message":"When using the UMD/global build from a script tag, the library is available as `fs.FetchScheduler`, not `FetchScheduler` directly. Named exports are not available.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Explicitly set `requestCount` to a value appropriate for your environment (e.g., 10 for Node.js, 6 for browser).","message":"The `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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Do not pass `signal` in fetch options; use the promise's `.cancel()` method instead.","message":"The `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.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.4.0':22 'allow':23 'api':87,110 'applic':103 'batch':111 'browser':18 'built':80 'built-in':79 'bundl':46 'cancel':35,75 'class':93 'compar':59 'concurr':27 'createfetch':70 'data':101 'data-heavi':100 'dedic':69 'definit':58 'easi':96 'esm':43 'excess':31 'fetch':2,14,28 'fetch-schedul':1 'heavi':102 'import':50 'includ':56 'individu':34 'integr':98 'javascript':113 'larg':11 'librari':6 'lightweight':5 'limit':26 'load':108 'main':92 'make':94 'manual':64 'map':107 'method':71 'minim':86 'node.js':20 'number':12 'offer':78 'one':91 'packag':40 'pool':62 'process':112 'promis':61,76 'provid':67 'queue':30 'remov':37 'request':15,29,32,38 'return':73 'schedul':3,8 'script':52 'ship':41 'statist':82 'surfac':88 'tag':53 'throttl':10,65 'tile':106 'typescript':57 'umd':45 'usag':54 'version':21 'work':47","created_at":"2026-06-07T16:52:35.565010+00:00","updated_at":"2026-06-07T16:52:35.565010+00:00","problems":[{"fix":"Use named import: `import { FetchScheduler } from 'fetch-scheduler';`","cause":"Using default import instead of named import: `import FetchScheduler from 'fetch-scheduler'` but there is no default export.","error":"Uncaught TypeError: fetchScheduler.createFetch is not a function"},{"fix":"Use `const FetchScheduler = window.fs.FetchScheduler;` or `const { FetchScheduler } = window.fs;`","cause":"Using the global script but trying to access `new FetchScheduler()` directly; the global is `fs`.","error":"ReferenceError: FetchScheduler is not defined"},{"fix":"Store the promise: `const p = scheduler.createFetch(...); p.cancel();`","cause":"Attempting to cancel the response promise (e.g., `scheduler.createFetch(...).then(...)`) instead of the original promise returned by `createFetch`.","error":"TypeError: promise.cancel is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/deyihu/fetch-scheduler#readme","github":"https://github.com/deyihu/fetch-scheduler","docs":null,"changelog":null,"pypi":null,"npm":"fetch-scheduler","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}