Async.Parallel or Array.Parallel.Map?

前端 未结 2 1323
别跟我提以往
别跟我提以往 2021-02-04 11:13

I\'m trying to implement a pattern I read from Don Syme\'s blog

(https://blogs.msdn.microsoft.com/dsyme/2010/01/09/async-and-parallel-design-patterns-in-f-parallelizing-

2条回答
  •  不要未来只要你来
    2021-02-04 11:57

    @Tomas already has a great answer. I'll just say a couple bits in addition.

    The idiom for F# asyncs is to name the method with an "Async" prefix (AsyncFoo, not FooAsync; the latter is an idiom already used by another .NET technology). So your functions should be getStockData and asyncGetStockData.

    Inside an async workflow, whenever you use let! instead of let or do! instead of do, the thing on the right should have type Async instead of T. Basically you need an existing async computation in order to 'go async' at this point in the workflow. Each Async will itself be either some other async{...} workflow, or else an async "primitive". The primitives are defined in the F# library or created in user code via Async.FromBeginEnd or Async.FromContinuations which enable defining the low-level details of starting a computation, registering an I/O callback, releasing the thread, and then restarting the computation when getting called back. So you have to 'plumb' async all the way down to some truly-async-I/O-primitive in order to get the full benefits of async I/O.

提交回复
热议问题