News for hackers. Stuff that matters.
Re:Ask HN: Why can't await be used from non-async functions? by Merad on Monday February 28, 2022 @01:44PM (#30503401)
Note that it's recommend that you avoid using these because they carry a risk of deadlock. Unless something has changed recently .Net doesn't have a 100% safe way to synchronously call an async method from a non-async method.
Re:Ask HN: Why can't await be used from non-async functions? by klodolph on Monday February 28, 2022 @01:53PM (#30503498)
I mean, depends on what you mean by "100% safe". You can synchronously wait from a thread that's not in the thread pool executing the tasks. Obviously that's not sufficient for safety, but it should be illustrative that safety is possible. There are also some issues with using .Wait or .Result but those can be solved.
Re:Ask HN: Why can't await be used from non-async functions? by endorphine on Monday February 28, 2022 @04:00PM (#30505066)
Can you elaborate on why there's a risk of a deadlock?
Re:Ask HN: Why can't await be used from non-async functions? by Merad on Monday February 28, 2022 @10:59PM (#30509317)
The very short version is that by synchronously blocking on the async method your thread may end up holding a resource (thread context info or the calling thread itself) that the async method needs in order to run its continuations. Here are a couple of more detailed explanations:

https://blog.stephencleary.com/2012/07/dont-block-on-async-c...

https://devblogs.microsoft.com/pfxteam/await-and-ui-and-dead...

Re:Ask HN: Why can't await be used from non-async functions? by endorphine on Tuesday March 01, 2022 @02:05AM (#30510629)
Now that's pretty much the answer I was looking for, I believe. This makes things much clearer!