Skip to main content
Version: 1.13.1

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

ParameterTypeDescription
fetcher() => Promise<AccessToken>Called when the cached token is missing or expired. MUST return a fresh AccessToken.
initial?AccessTokenOptional 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>