mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 13:33:13 +00:00
1.2.7
This commit is contained in:
40
Esiur/Core/AsyncAwaiter.cs
Normal file
40
Esiur/Core/AsyncAwaiter.cs
Normal file
@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user