-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Asynchronous action execution
For an overview of syntax and policies available, read first the readme: https://github.com/App-vNext/Polly#asynchronous-support-net-45-and-pcl-only. This article describes the asynchronous operation of policies in detail.
Asynchronous action execution is available in .NET4.5 and PCL.
In general, asynchronous policies execute actions in the same manner as synchronous policies. The following are the differences:
In asynchronous execution, all delegates are async
and run with await
.
As recommended for libraries offering an async API, by default, async continuations (when a method resumes from await
) are not run on a captured synchronization context. However, if you require the whole .ExecuteAsync(…)
call to continue on the captured synchronization context, use the overloads taking a bool continueOnCapturedContext
, setting this to true
.
Using an .ExecuteAsync(…)
(or similar) method taking a CancellationToken
allows async action execution to be cancelled. Cancellation can occur:
-
Before the delegate is actioned at all: In common with the Base Class Library implementation in
Task.Run(…)
, if the cancellation token is cancelled before execution begins, the delegate is not executed at all. -
During delegate execution: The action delegates taken by the relevant
.ExecuteAsync(…)
overloads take aCancellationToken
input parameter. Using this input parameter, theCancellationToken
passed in to.ExecuteAsync(…)
call is in turn passed in to (and can control cancellation within) the action delegate. - During any wait between retries.
All cancellation throws the usual OperationCanceledException
.
- Home
- Polly RoadMap
- Contributing
- Transient fault handling and proactive resilience engineering
- Supported targets
- Retry
- Circuit Breaker
- Advanced Circuit Breaker
- Timeout
- Bulkhead
- Cache
- Rate-Limit
- Fallback
- PolicyWrap
- NoOp
- PolicyRegistry
- Polly and HttpClientFactory
- Asynchronous action execution
- Handling InnerExceptions and AggregateExceptions
- Statefulness of policies
- Keys and Context Data
- Non generic and generic policies
- Polly and interfaces
- Some policy patterns
- Debugging with Polly in Visual Studio
- Unit-testing with Polly
- Polly concept and architecture
- Polly v6 breaking changes
- Polly v7 breaking changes
- DISCUSSION PROPOSAL- Polly eventing and metrics architecture