Skip to main content

Chapter 11: Guidelines for designing asynchronous APIs

In this chapter

  • Naming and signatures: the Async suffix and cancellation conventions
    • Public asynchronous operations should usually have the Async suffix
    • If cancellation is supported, provide an overload that accepts CancellationToken and pass it all the way through
    • Do not design public APIs as async void
  • 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 ValueTask is appropriate and its limitations
    • The advantage of ValueTask
    • The limitations of ValueTask
  • Guidelines for ConfigureAwait(false) as a library author
  • IAsyncDisposable and the lifetime of owned resources
  • Conclusion

This chapter is not available in the free preview. Purchase the book to read the complete edition now.

Buy this book