API Reference
Constructor
typescript
new AsyncLoader<T, M = Record<string, any>>(
loader: IAsyncLoader<T, M> | IAsyncLoader<T, M>[],
options?: AsyncLoaderOptions<T, M>
)loader: the underlying loader function (single or array), receiving a merged abort signal viaargs.abortSignal; may returnPromise<T>or a synchronous valueT. With multiple loaders, orchestrate viamultiLoaderStrategy(see Multi-Loader).options: constructor options, see Options.
Instance methods
| Method | Description |
|---|---|
get(args?) | Get the result; auto-triggers loading on first call / cache stale / last failure. args is forwarded to the internal signal (timeout is a wait timeout, semantically different from options.timeout) |
load() | Trigger a load (usually no need to call manually; get() triggers it automatically) |
refresh(args?) | Force a reload ignoring fresh cache; aborts any inflight load first, then reloads and returns the new result. args is forwarded to the internal signal |
invalidate() | Mark the data stale: clears the cache entry and resets a completed signal, so the next get() reloads. Does not trigger loading immediately. Unlike clear(), it also works without a cache (cache=0) |
abort() | Abort loading, penetrating to the underlying request; also terminates any pending retry wait |
clear() | Clear the current instance's cache entry |
clearAll() | Clear all cache entries in the shared storage |
isPending() | Whether loading is in progress (including retries); based on loading |
isFulfilled() | Whether the load succeeded (including defaultValue fallback) |
isRejected() | Whether the load failed (business error / timeout / abort) |
Static methods
| Method | Description |
|---|---|
AsyncLoader.resolve(result) | Create a preset-fulfilled instance: get() returns result directly without loading (see Static Methods) |
AsyncLoader.reject(error) | Create a preset-rejected instance: get() throws error directly without loading (see Static Methods) |
AsyncLoader.clearLoaderCache() | Clear the multiplex inflight-instance cache; mainly for test isolation between cases sharing a hash |
Instance properties
| Property | Description |
|---|---|
signal | The internal IAsyncSignal carrying the result; observe its state and result / error |
loading | Whether a load (including retries) is in progress |
loader | The underlying loader function (single or array, constructor's first argument) |
hash | The cache/multiplex key (explicit or auto-generated) |
options | The merged constructor options |
Error types
| Trigger | Error type |
|---|---|
| Timeout final failure (retries exhausted or retry disabled) | TimeoutError |
Manual abort() / external abortSignal | AbortError |
| Business error | The original error is propagated as-is |