gpt4 book ai didi

.net - 什么值得期待?

转载 作者:行者123 更新时间:2023-12-03 15:38:21 26 4
gpt4 key购买 nike

我听说 awaitable 是一种异步操作。但是既然是一个重要的概念,为什么我在 MSDN 上找不到准确的定义呢?

我的问题不是如何编写 async/await。我的问题是了解这个概念。 MSDN有概念async/await但没有 awaitable .

那么什么是可等待的呢?如果是手术,包括什么?

最佳答案

最后我在 Async/Await FAQ. 上找到了它

An “awaitable” is any type that exposes a GetAwaiter method which returns a valid “awaiter”. This GetAwaiter method may be an instance method (as it is in the case of Task and Task<TResult>), or it may be an extension method.

An “awaiter” is any type returned from an awaitable’s GetAwaiter method and that conforms to a particular pattern. The awaiter must implement the System.Runtime.CompilerServices.INotifyCompletion interface, and optionally may implement the System.Runtime.CompilerServices.ICriticalNotifyCompletion interface. In addition to providing an implementation of the OnCompleted method that comes from INotifyCompletion (and optionally the UnsafeOnCompleted method that comes from ICriticalNotifyCompletion), an awaiter must also provide an IsCompleted Boolean property, as well as a parameterless GetResult method. GetResult returns void if the awaitable represents a void-returning operation, or it returns a TResult if the awaitable represents a TResult-returning operation.


还有这个 link about awaitable and awaiter is helpful.

关于.net - 什么值得期待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40853158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com