Open optikos opened 6 years ago
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
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 anawait
, 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 ofawait
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 eachasync
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 anasync
subroutine. In variant 1, Kenny Kerr'simplements<MyAsync, IAsyncAction, IAsyncInfo>
seems to be similar to the callback alternative that you mention on theREADME.md
regarding your current busy-wait-loop approach to an analogue ofawait
in Ada.