StephenCleary / AsyncEx

A helper library for async/await.
MIT License
3.49k stars 358 forks source link

Double awaits in a few places #252

Closed tvass83 closed 2 years ago

tvass83 commented 2 years ago

Thanks @StephenCleary for bringing us this great library, really appreciate it!

I was wondering, could we omit the outer await and simply return the result of the inner one? Would that be identical and if so, emit simpler IL code? https://github.com/StephenCleary/AsyncEx/blob/0361015459938f2eb8f3c1ad1021d19ee01c93a4/src/Nito.AsyncEx.Tasks/TaskExtensions.cs#L32-L36

StephenCleary commented 2 years ago

I don't see how that would work. The inner await returns a task that may be complete, faulted, or canceled; and the outer await detects faults/cancellations and raises the appropriate exception.

Feel free to re-open if I've misunderstood something.

tvass83 commented 2 years ago

@StephenCleary You are absolutely right, thanks for the "clearyfication"! 😀

abarberenaCPDS commented 2 years ago

@StephenCleary You are absolutely right, thanks for the "clearyfication"! 😀

Hi @tvass83, I found your post very interesting and familiar. One of my devs used to code this way, however, it was very difficult to debug the code.

What helped us all was to review @StephenCleary cookbook and blogs. First, understanding the programming model around tasks and awaitables. We agreed to first declare Task variables and then await. not only improved the code readability, but it also improved our debugging and testing process.

What we found also very helpful in our organization, was to give some training to our devs on CPU-bound vs IO-bound operations. In summary, when the devs grokked the concepts, they thrilled on developing and delivering the project.

HTH.