Chapter 11: Guidelines for designing asynchronous APIs
In this chapter
- Naming and signatures: the
Asyncsuffix and cancellation conventions- Public asynchronous operations should usually have the
Asyncsuffix - If cancellation is supported, provide an overload that accepts
CancellationTokenand pass it all the way through - Do not design public APIs as
async void
- Public asynchronous operations should usually have the
- Choosing between synchronous and asynchronous APIs
- Rule 1: never wrap async code just to pretend it is synchronous
- Rule 2: never wrap synchronous work just to pretend it is asynchronous
- Conclusion: provide the version the operation truly needs
- Exception, cancellation, and timeout semantics
- When exceptions should be thrown
- Do not use exceptions as ordinary control flow
- Distinguishing timeout from cancellation
- When
ValueTaskis appropriate and its limitations- The advantage of
ValueTask - The limitations of
ValueTask
- The advantage of
- Guidelines for
ConfigureAwait(false)as a library author IAsyncDisposableand the lifetime of owned resources- Conclusion
This chapter is not available in the free preview. Purchase the book to read the complete edition now.