Quick Start
AsyncSignal ships with two modules: asyncSignal and AsyncLoader. The former is a reusable async signal; the latter wraps load / cache / abort / timeout / retry around a data loader.
asyncSignal: a reusable signal
Like Promise.withResolvers(), but resettable and manually resolvable / rejectable:
typescript
import { asyncSignal } from "asyncsignal";
const signal = asyncSignal();
// Wait for the signal to resolve or reject
await signal();
// Resolve the signal
signal.resolve("resolved value");
// Or reject the signal
signal.reject(new Error("rejected error"));Continue with:
- Static Methods — create pre-resolved / pre-rejected signals
- Timeout — wait with a timeout
- Abort Behavior — integration with AbortController
- Full API Reference
AsyncLoader: a loader with cache and retry
The first constructor argument is the underlying loader function, which receives a merged abort signal via args.abortSignal:
typescript
import { AsyncLoader } from "asyncsignal/loader";
const loader = new AsyncLoader(async (args) => {
const r = await fetch("/api/data", { signal: args.abortSignal });
return await r.json();
});
const data = await loader.get(); // get the result (returns cached value if fresh)
loader.abort(); // abort loadingContinue with:
- Options — cache / timeout / retry / multiplex, etc.
- Caching — cache results by hash
- Retry — auto-retry on failure
- Multiplexing — deduplicate concurrent loads
- Full API Reference
Next Steps
- Explore the AsyncSignal features
- Explore the AsyncLoader features