How does F#'s async really work?

前端 未结 6 1075
逝去的感伤
逝去的感伤 2020-12-23 17:01

I am trying to learn how async and let! work in F#. All the docs i\'ve read seem confusing. What\'s the point of running an async block with Async

6条回答
  •  一整个雨季
    2020-12-23 17:38

    Lots of great detail in the other answers, but as I beginner I got tripped up by the differences between C# and F#.

    F# async blocks are a recipe for how the code should run, not actually an instruction to run it yet.

    You build up your recipe, maybe combining with other recipes (e.g. Async.Parallel). Only then do you ask the system to run it, and you can do that on the current thread (e.g. Async.StartImmediate) or on a new task, or various other ways.

    So it's a decoupling of what you want to do from who should do it.

    The C# model is often called 'Hot Tasks' because the tasks are started for you as part of their definition, vs. the F# 'Cold Task' models.

提交回复
热议问题