有没有写使用新的异步.NET API的任何指引/等待功能 [英] Are there any guidelines for writing .NET APIs using the new async/await features
问题描述
我目前正在设计一些内部API,我使用异步CTP和新等待
/ 异步
关键词。
I'm currently designing some internal APIs where I use the Async CTP and its new await
/async
keywords.
有没有关于如何将这些API应该在设计的任何准则或最佳做法?
Are there any guidelines or best practices on how these APIs should be designed?
具体做法是:
- 我应该同时提供同步和方法的异步版本? (即
任务DoStuffAsync()
的和的无效DoStuff()
- 如果所有的异步方法我可以公开的形式
异步任务< T> GetStuffAsync()
(即方法名末尾带异步
)或者是确定有东西名为GetStuff()
是awaitable?
- Should I provide both a synchronous and an asynchronous version of methods? (i.e.
Task DoStuffAsync()
andvoid DoStuff()
- Should all async methods I expose be in the form
async Task<T> GetStuffAsync()
(i.e. method name end withAsync
) or is it ok to to have something namedGetStuff()
be awaitable?
我不明白,这还不是全部黑色或白色在这里,它取决于问题的方法,但是我正在寻找的一般准则。
I do understand that it's not all black or white here, and that it depends on the method in question, but I'm looking for general guidelines.
推荐答案
好不容易找到了掘金队,大多数出版物都集中在客户端编程方面。好东西是:
Hard to find the nuggets, most publications are focused on the client programming side. Good stuff is:
- A white paper titled The Task-based Asynchronous Pattern. Download is here (note: slow to respond this morning).
- Stephen Toub had a presentation at Windows Build that talked about optimizing the pattern, many important hints. There's a video, also available in print.
请记住,这是所有preVIEW,重要的细节可能会在此之前的船舶发生改变。
Do keep in mind this is all preview, important details may change before this ships.
这篇关于有没有写使用新的异步.NET API的任何指引/等待功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!