Default Value
On final failure (business error, or timeout after retries are exhausted), providing defaultValue swallows the error and resolves the fallback instead.
typescript
const loader = new AsyncLoader(fetchUser, { defaultValue: defaultUser });
const user = await loader.get(); // on failure, resolves defaultUser instead of throwingNotes
- Falsy values (
0/""/null/false) are valid fallbacks when explicitly provided. - Has no effect on manual
abort()(still rejects withAbortError). - The fallback is not written to the cache, so the next
get()reloads to fetch the real value.
When the fallback triggers
| Scenario | Triggers defaultValue? |
|---|---|
| Business error (after retries exhausted) | ✅ Yes |
| Timeout (after retries exhausted) | ✅ Yes |
Manual abort() | ❌ No (rejects with AbortError) |
Relationship with onFulfilled
When the fallback triggers, onFulfilled is still called with the fallback as result — success and fallback share a unified "success" semantics for callers.