Repository navigation
Fallback
Arnel Robles edited this page Sep 29, 2026
·
1 revision
Package: Carom.Extensions. Extension methods on Func<T> and Func<Task<T>>.
using Carom.Extensions;
// A constant
var config = await new Func<Task<AppConfig>>(() => configService.LoadAsync())
.PocketAsync(AppConfig.Default);
// Computed from the exception
var price = new Func<decimal>(() => pricing.Get(sku))
.Pocket(ex => cache.LastKnownPrice(sku));
// Retry first, then fall back
var rates = await CaromFallbackExtensions.ShotWithPocketAsync(
() => fx.GetRatesAsync(), fallback: Rates.Empty, retries: 3);The async overloads take a CancellationToken. When that token is cancelled the OperationCanceledException is rethrown, not replaced with the fallback, so a caller who cancels is not handed a default value as if the call had worked.
The synchronous Pocket overloads have no token and fall back on any exception, cancellation included.
For a typed fallback in a named pipeline, use AddFallback<TResult> on the DI pipeline. It only applies when the pipeline's result type is TResult.
Written from the Carom source. The repository is the source of truth; if a page disagrees with the code, the code wins. Licensed MPL-2.0.
Core
Carom.Extensions
Integrations
Project