Created
August 3, 2017 23:55
-
-
Save pakrym/e9fc0a6babfaa259fc79310a53a643f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using System.Runtime.CompilerServices; | |
namespace refreturnawaitable | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hello World!"); | |
new C().M().Wait(); | |
} | |
} | |
public class C { | |
public A _a; | |
public async Task M() { | |
_a = new A(this); | |
await DoAsync(); | |
Console.WriteLine(_a._i); | |
} | |
public ref A DoAsync() | |
{ | |
return ref _a; | |
} | |
} | |
public struct A: ICriticalNotifyCompletion | |
{ | |
private C _c; | |
public int _i; | |
public A(C c) | |
{ | |
_c = c; | |
_i = 0; | |
} | |
public ref A GetAwaiter(){ | |
return ref _c._a; | |
} | |
public void UnsafeOnCompleted(Action continuation) | |
{ | |
OnCompleted(continuation); | |
} | |
public void OnCompleted(Action continuation) | |
{ | |
_i ++; | |
continuation(); | |
} | |
public bool IsCompleted => false; | |
public void GetResult() | |
{ | |
_i ++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment