Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#'s await is not a busy-wait loop retrying periodically #4

Open
optikos opened this issue Apr 14, 2018 · 1 comment
Open

C#'s await is not a busy-wait loop retrying periodically #4

optikos opened this issue Apr 14, 2018 · 1 comment

Comments

@optikos
Copy link

optikos commented Apr 14, 2018

This issue is food for thought as a design for Ada's analogue of C#'s await. Since Roslyn generates a lambda (anonymous local function) to implement an await, it is conceivable that the Ada-WinRT binding-generator tool could generate an analogous •named• (i.e., not-lambda) Ada subroutine to be called (back) when the operation completes. The lack of name is mere convenience in the lambda. Indeed even being a local function seems to be mere convenience in the lambda at the heart of await because that generated lambda seems to not absolutely crucially need to bind to any data allocated on the call-stack, other than to provide some sort of context to identify multiple concurrent invocations of the same async subroutine.

This posting on StackOverflow seems to be a lucid description of how C#'s await works (well) under the hood. Since Ada-WinRT has a code-generator at its disposal, some of the same tricks that Roslyn does as a compiler with an AST, the Ada-WinRT could conceivably (at least partially, with generated named subroutines, lay similar groundwork to) do for each async method in WinRT components.

Also, this blog posting is Kenny Kerr's intro to 1) a callback interface-mixin solution and 2) a co-routine solution to how the analogue of C#'s await could appear in C++/WinRT for an async subroutine. In variant 1, Kenny Kerr's implements<MyAsync, IAsyncAction, IAsyncInfo> seems to be similar to the callback alternative that you mention on the README.md regarding your current busy-wait-loop approach to an analogue of await in Ada.

@Alex-Gamper
Copy link
Owner

I had researched C# implementation of await/async and it seems to (as you correctly pointed out) use
Roslyn to generate a internal FSM ? As an alternative I simply setup a busy-wait in the OCR sample, just
to demonstrate the simplest method. In the Network example I use a different approach, ie a Callback,
but this is still currently a busy wait. A better approach would be to do a blocking wait on a signal, which
is raised by the completion Callback/routine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants