Support for Mono Continuations (Microthreads) as opposite to Async/Await

Topics: C# Language Design
Jul 24, 2014 at 10:42 AM
There are the document that explains use case of Mono Continuations (Microthreads) for variety of cases:
Jul 24, 2014 at 2:53 PM
I don't really see how this differs from async/await, or couldn't be implemented on top of async/await. Those keywords really only provide the syntax candy for establishing continuations and returning the eventuality of completion. Under the hood that could be accomplished through TaskCompletionSource<T>, custom awaiters, custom schedulers or a variety of other mechanisms. I've implemented something akin to fibers myself using async/await.
Jul 24, 2014 at 9:31 PM
  1. Calling async function create garbage because any async function is object with state machine and every call create new such object. Mono Continuations does not create garbage.
  2. In mono continuations functions doe's not need to be async for awaiting ability, and we can suspend not only one async function but part of call stack so we can write
private void SomeLogic( )
    WaitForObjectVisible (princess);
    WalkTo (princess);
    Kiss (princess);

private void WalkTo (Princess princess)
    Walker.WaitWalkToPoint( princess.position );
And I don't care how many methods between SomeLogic and method that suspend execution, it is work mostly like Thread.Suspend, and when we have restore we just continue execution and then properly return to WalkTo and then to SomeLogic...
Aug 3, 2014 at 6:51 AM
Async state machines are structs, not reference types.
Aug 7, 2014 at 1:57 PM
It is does not matter.
If I write custom awaiter i.e. HttpRequestAsync that will save continuation action and call it later and maybe in another thread than state machine struct will be boxed to Heap and therefore creates garbage.

And Also this code cause StackOverflowException if awaiter can return result synchronously:
for( var i = 0; i < 10000000; i++ )
    result += await new SomeAwaiter( );
Mono Microthreads don't have this disadvantages