C#C
C#8mo ago
LastExceed

consolidating my understanding of `async`/`await` in C# and Rust

Please confirm or correct the following:

  1. A Future represents a workload that has yet to be done
  2. C# doesn't use Futures (at least not remotely as ubiquitous as Rust)
  3. "Spawning" (e.g. via tokio::spawn(my_future)) begins (and ONLY begins) the execution of such a workload, and returns a Task that represents the execution
  4. Calling an async C# function which returns a Task is analog to immediately spawning the future returned by an async Rust function
  5. A Task calling await on another Task is analog (but NOT equivalent) to a Thread calling .Join() on another Thread (except that the join handle of a C# Thread cannot convey a result, so the analogy fails for Task<T>)
  6. .ConfigureAwait(false) in C# is analog to using a multi-threaded runtime in Rust, and indicates that the workload may be executed not only concurrently, but also in parallel. This distinction is mostly relevant for context dependent workloads (e.g. some platforms restrict UI manipulation to the main thread), but also affects whether or not data races can occur
  7. Exceptions thrown in async functions are automatically catched, stored in the returend Task object, and rethrown on await
  8. calling an async void method is like calling an async Task and discarding the returned Task object, except that exceptions aren't catched, and can instead kill the entire thread
Was this page helpful?