vulcanmind
v1.0.0
Published
Zero-dependency async utilities: memoize with TTL, exponential-backoff retry, throttle, debounce, once.
Maintainers
Readme
vulcanmind
A zero-dependency set of async utilities for Node.js: memoization with TTL, exponential-backoff retry, throttle, debounce, and run-once. A reliable little "mind" that remembers results and retries resolutely.
Pricing
Free. MIT-licensed, open source. No fees, no tiers.
Install
npm install vulcanmindUsage
const { memoize, retry, throttle, debounce, once } = require("vulcanmind");
// Memoize an expensive async call for 60 seconds
const getUser = memoize(async (id) => fetchUser(id), { ttl: 60_000 });
const a = await getUser(1); // hits the source
const b = await getUser(1); // served from cache
getUser.clear(); // drop all cached results
// Retry a flaky call with exponential backoff (100ms, 200ms, 400ms...)
const data = await retry(() => callFlakyApi(), {
retries: 4,
factor: 2,
minDelay: 100,
maxDelay: 2000,
shouldRetry: (err) => err.status >= 500,
onRetry: (err, n) => console.log(`retry ${n}:`, err.message),
});
// Rate-limit an event handler
const onScroll = throttle(() => save(), 500);
// Debounce a search box
const onType = debounce(() => runSearch(), 300);
// Run an initializer exactly once
const init = once(() => connectDb());API
memoize(fn, { ttl, keyFn, maxSize })→ wrapped with.clear(),.delete(),.size()retry(fn, { retries, factor, minDelay, maxDelay, shouldRetry, onRetry })→ Promisethrottle(fn, wait)·debounce(fn, wait)·once(fn)
License
MIT © shinnjr
