Function: createCantonMemoizedTokenFetcher()
createCantonMemoizedTokenFetcher(
fetcher: () =>Promise<AccessToken>,initial?:AccessToken): () =>Promise<AccessToken>
Defined in: canton/authentication/token-source.ts:136
Create a memoized async token fetcher that caches the result until the token expires, coalesces concurrent callers onto a single in-flight promise, and auto-removes the cache entry on rejection.
Uses micro-memoize with { async: true } for promise coalescing and
rejection-based cache invalidation. Token expiry is tracked via a
lastToken closure variable; when expired, the cache is cleared so the
next call re-fetches.
Parameters
| Parameter | Type | Description |
|---|---|---|
fetcher | () => Promise<AccessToken> | Called when the cached token is missing or expired. MUST return a fresh AccessToken. |
initial? | AccessToken | Optional initial token (returned on the first call without fetching, when still valid). |
Returns
A memoized () => Promise<AccessToken> that caches until the
returned token's expiresAt passes (accounting for skew).
() => Promise<AccessToken>