Registry / devops / throttle-async-function

throttle-async-function

JSON →
library1.2.0jsnpmunverified

throttle-async-function (v1.2.0) is an npm package that caches the results of async function calls based on arguments, effectively throttling execution by serving cached results for repeated calls. It offers configurable cache refresh period, max age, LRU eviction, retry on failure, and hit rate reporting. Unlike simple memoization libraries, it includes a cache refresh mechanism that proactively re-fetches data while still serving stale results, and exposes utilities like callWithoutCache and clearCache. The package has a low release cadence with no major changes since initial release.

npm install throttle-async-function
INSTALL
IMPORT
SIG · THROTTLE-ASYNC-FUN
T
throttle-async-function
devopsjavascriptv1.2.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.

throttleAsyncFunction
import throttleAsyncFunction from 'throttle-async-function'
const { throttleAsyncFunction } = require('throttle-async-function')
Default export, not named. In CommonJS use require('throttle-async-function') directly.
throttleAsyncFunction
const throttleAsyncFunction = require('throttle-async-function')
CommonJS usage

Creates a throttled async function with caching, shows cache reuse, force refresh, and cache clearing.

import throttleAsyncFunction from 'throttle-async-function'; const throttled = throttleAsyncFunction( async (userId) => { const response = await fetch(`https://jsonplaceholder.typicode.com/users/${userId}`); return response.json(); }, { cacheRefreshPeriod: 10 * 1000, cacheMaxAge: 60 * 1000, maxCachedItems: 1000, retryCount: 2, } ); // First call executes the wrapped function const user1 = await throttled(1); console.log('User 1:', user1.name); // Second call with same argument returns cached result const user1Again = await throttled(1); console.log('Same result:', user1Again.name); // Different argument triggers new execution const user2 = await throttled(2); console.log('User 2:', user2.name); // Force cache refresh const refreshedUser1 = await throttled.callWithoutCache(1); console.log('Refreshed:', refreshedUser1.name); // Clear entire cache throttled.clearCache(); // After clearing, fetch again const user1AfterClear = await throttled(1); console.log('After clear:', user1AfterClear.name);
Debug
Known issues
gotchaThe package name suggests throttling but actually caches results; no rate limiting or concurrency control is applied.
fix
For actual rate limiting, use a dedicated throttle package like p-limit.
affects: >=1.0.0
gotchaIf the async function throws or rejects, the cache is not updated; the error propagates after retries (if configured).
fix
Ensure your async function handles errors and does not throw for expected failures.
affects: >=1.0.0
breakingOptions object defaults changed between versions? Not documented.
fix
Always specify options explicitly to avoid relying on default values.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: throttleAsyncFunction is not a function
Using named import instead of default import in ES modules.
fix
Use default import: import throttleAsyncFunction from 'throttle-async-function'
Error: Cannot find module 'lru-cache'
lru-cache is a peer dependency not automatically installed.
fix
Install lru-cache explicitly: npm install lru-cache
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
lru-cacheoptionalUsed for LRU cache eviction when maxCachedItems is set
Agent activity
6 hits · last 30 days
node
6
Resources
throttle-async-function — npm install throttle-async-function · libregistry