StephenCleary / AsyncEx

A helper library for async/await.
MIT License
3.52k stars 356 forks source link

Add WaitAndUnwrapException for ValueTask #246

Open GSPP opened 2 years ago

GSPP commented 2 years ago

This is a useful little helper method. Would be useful for ValueTask, too.

StephenCleary commented 2 years ago

There are some APIs in this library (like WaitAndUnwrapException) that are not really recommended, but included either for historical reasons or because they've got some sharp corners in their implementation.

It may make sense to bring this API forward for ValueTask, but I'll have to think about it. It also wouldn't be recommended, and the implementation is the same as the workaround for the missing API: just call AsTask followed by WaitAndUnwrapException. I'm leaning against including this API for ValueTask because waiting on value tasks isn't permitted (so this API would muddy the waters for devs learning about value tasks), but I'll think about it.

GSPP commented 2 years ago

Right, so my motivation is to use this in cases where sync-over-async is warranted. These cases do exist. It can be due to an interface, but it can also be useful in an application that does not benefit from async IO when you have to use an async-only library. Then, instead of infecting everything with async for zero gain, you just block in a few places. I understand that the .NET community has developed an outright disdain for doing so but I believe it to be a rational engineering choice.