-
-
Save ufcpp/0f0e17daef421ccc11c7529c041e7dd3 to your computer and use it in GitHub Desktop.
どこかでこんな風になってる感じがする
This file contains hidden or 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; | |
class Program | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("begin"); | |
// なんかどこかで誰かがこんな Post してる気配がなくもない | |
Post(() => | |
{ | |
X().Wait(); | |
Console.WriteLine("end"); | |
}); | |
_lastTask.Wait(); | |
} | |
static Task _lastTask = Task.FromResult<object>(null); | |
static void Post(Action continueation) | |
{ | |
var t = _lastTask.ContinueWith(_ => continueation()); | |
_lastTask = t; | |
} | |
static Task X() | |
{ | |
Console.WriteLine("X1"); | |
var tcs = new TaskCompletionSource<object>(); | |
/* ↓みたいなコードだったとして | |
* await Task.CompletedTask; | |
* await Task.Delay(10); | |
*/ | |
Task.CompletedTask.ContinueWith(_1 => | |
{ | |
Post(() => | |
{ | |
Console.WriteLine("X2"); | |
Task.Delay(10).ContinueWith(_2 => | |
{ | |
Post(() => | |
{ | |
Console.WriteLine("X3"); | |
tcs.TrySetResult(null); | |
}); | |
}); | |
}); | |
}); | |
return tcs.Task; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment