3

I'm trying to learn F# by diving straight in and attempting to convert some C# code to it. One of the things I'm rewriting is part of an async method, which awaits a call to HttpClient's GetAsync without using the result. That is:

await httpClient.GetAsync("http://www.example.com");

Below is the only thing I've tried which doesn't get the red squigglies. While I assume it's valid, it does create a variable which I'd probably want to avoid.

let! ignoreme = Async.AwaitTask <| httpClient.GetAsync("http://www.example.com")

How should this be done?

4

1 回答 1

5

do!运算符与 结合使用Async.Ignore

do! Async.AwaitTask(httpClient.GetAsync("http://www.example.com")) |> Async.Ignore

这与写入let! ignoreme = ...然后忽略ignoreme绑定相同。

不过,我认为最好还是坚持使用 F# 数据类型——尽量避免Async.AwaitTask直接使用该Async<'T>类型。我认为FSharp.Data 库会很有帮助。

于 2013-07-08T11:04:30.783 回答