Forum Discussion

adelarsq's avatar
adelarsq
Copper Contributor
Nov 12, 2021

F#: Tasks vs Async

With F# 6 now we have option to also using Tasks. Which are the drawbacks to use Tasks or Async?

Also appears that Tasks are faster. How much faster?

Thanks in advance.

  • pblasucci's avatar
    pblasucci
    Copper Contributor
    There was actually a bit of discussion about this on Twitter just a few days ago.

    TL; DR --
    The Task CE is meant to simplify cases where you have a lot of interop with other existing Task-based APIs (eg: you're writing an APS.NET Core middleware), or if lots of profiling dictates that Async CE is causing performance issues. But by and large, the Async CE should be preferred.

    Hope this helps! 🙂
  • MauricioCaspian's avatar
    MauricioCaspian
    Copper Contributor

    Async programming in F# is designed for lightweight and compositional asynchronous workflows, making it well-suited for tasks that involve I/O operations or waiting for external resources. It provides built-in exception handling and cancellation propagation, making it easier to manage errors and handle asynchronous operations.

Resources