Always use the 'async' and 'await' keywords in asynchronous methods in a library?

后端 未结 2 1185
我在风中等你
我在风中等你 2020-12-30 05:34

Summary: In a library method, when should I use the async and await keywords instead of returning a Task directly?

2条回答
  •  天命终不由人
    2020-12-30 06:16

    Don't take my word for it, because I never understood async/await that well, but what bothered me most about the idea was that all methods using async had to be marked as async as well, which annoyed me to no end.

    I guess in a library giving people the option to choose how to use the methods is a good thing, so you should use async, however I always found it more clear to explicitly use the Tasks directly.

提交回复
热议问题