Registry /
storage / abortable-promise-cache
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.
AbortablePromiseCache
✓ import AbortablePromiseCache from 'abortable-promise-cache'
✗ const { AbortablePromiseCache } = require('abortable-promise-cache')
Default export; named export in CJS is not available. Use default import ESM or default require.
default
✓ const AbortablePromiseCache = require('abortable-promise-cache').default
✗ const AbortablePromiseCache = require('abortable-promise-cache')
In CJS, the default export is under .default. Node >=6 supports require, but .default is needed for default export.
FillCallback
✓ No type export; define inline: async (data: any, signal: AbortSignal) => any
✗ import { FillCallback } from 'abortable-promise-cache'
The package does not export TypeScript types. You must define fill callback signature manually.
Creates a cache with a fill function that supports abort, then performs a cached get with an AbortController signal.
import AbortablePromiseCache from 'abortable-promise-cache';
import QuickLRU from 'quick-lru';
const cache = new AbortablePromiseCache({
cache: new QuickLRU({ maxSize: 1000 }),
async fill(requestData, abortSignal) {
// Simulate long-running task that respects abort signal
return new Promise((resolve, reject) => {
const timeout = setTimeout(() => resolve('done'), 1000);
abortSignal.addEventListener('abort', () => {
clearTimeout(timeout);
reject(new Error('Aborted'));
});
});
}
});
async function example() {
const controller = new AbortController();
const result = await cache.get('key', { some: 'data' }, controller.signal);
console.log(result);
}
example();
Errors
Common errors & fixes
TypeError: cache.keys is not a function
The backing cache provided does not have a keys() method.
fixUse a cache like quick-lru that implements keys(), or create an adapter with a keys method returning an iterator.
Module not found: Can't resolve 'abortable-promise-cache'
Package not installed or incorrect import path.
fixRun `npm install abortable-promise-cache --save` and ensure import/require uses correct syntax (see imports).
AbortablePromiseCache is not a constructor
In CommonJS, using require('abortable-promise-cache') without .default.
fixUse `const AbortablePromiseCache = require('abortable-promise-cache').default;` Audit
Dependencies
quick-lruoptionalrecommended backing cache; any cache adapter with get/set/delete/keys works