Stream: C#/.net-collaboration

Topic: single-threaded async/await


view this post on Zulip Joel Dice (May 29 2024 at 16:43):

Is anybody here an expert on async/await in C#/.NET? I'm trying to support it in WASI using wasi:io/poll to drive await continuations, but my experiments so far implementing a custom SynchronizationContext and/or custom TaskScheduler aren't working.

All the examples I've found so far seem to assume there are at least two threads in play. I think it should be possible to do everything in a single thread, but I haven't figured out how to hook everything up.

view this post on Zulip Notification Bot (May 29 2024 at 17:36):

A message was moved here from #C#/.net-collaboration > replacing emsdk with wasi-sdk by Joel Dice.

view this post on Zulip Joel Dice (May 29 2024 at 17:37):

Nevermind, I figured it out. The key was to use TaskCreationOptions.AttachedToParent to ensure the child tasks finish before the parent task finishes.

view this post on Zulip Scott Waye (May 30 2024 at 09:44):

no problem, feel free to create noise :-)

view this post on Zulip Joel Dice (May 30 2024 at 19:19):

Ok, so I hit a real (i.e. not just self-inflicted) roadblock this time: https://github.com/dotnet/runtime/issues/102894
I'd love to get feedback on that from the .NET experts.

I've been working to support async/await in C# for doing concurrent I/O when targeting WASIp2. A key piece of that is the wasi:io/poll#poll function, which accepts an arbitrary number of pollable h...

view this post on Zulip Joel Dice (May 30 2024 at 22:19):

While I still think the above is a real issue, I worked around it by implementing my own WhenEach combinator. Here's an example that does concurrent outbound request streaming: https://github.com/dicej/dotnet9-wasi-http-example/blob/snapshot/App.cs

Contribute to dicej/dotnet9-wasi-http-example development by creating an account on GitHub.

Last updated: Dec 13 2025 at 20:04 UTC