Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Last active August 24, 2016 06:58
Show Gist options
  • Save ufcpp/0f0e17daef421ccc11c7529c041e7dd3 to your computer and use it in GitHub Desktop.
Save ufcpp/0f0e17daef421ccc11c7529c041e7dd3 to your computer and use it in GitHub Desktop.
どこかでこんな風になってる感じがする
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