2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
esiur-dotnet/Esiur/Core/AsyncAwaiter.cs
2019-08-07 05:18:27 +03:00

41 lines
803 B
C#

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace Esiur.Core
{
public class AsyncAwaiter<T> : INotifyCompletion
{
public Action callback = null;
public T result;
private bool completed;
public AsyncAwaiter(AsyncReply<T> reply)
{
reply.Then(x =>
{
this.completed = true;
this.result = x;
this.callback?.Invoke();
});
}
public T GetResult()
{
return result;
}
public bool IsCompleted => completed;
public void OnCompleted(Action continuation)
{
// Continue....
callback = continuation;
}
}
}