mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
New awaiters
This commit is contained in:
parent
ed34ae229d
commit
c8bec085a4
@ -14,6 +14,16 @@
|
|||||||
<Version>1.3.0</Version>
|
<Version>1.3.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="MongoDBStore.cs" />
|
||||||
|
<Compile Remove="MongoDBStoreGeneric.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="MongoDBStore.cs" />
|
||||||
|
<None Include="MongoDBStoreGeneric.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MongoDB.Bson" Version="2.9.1" />
|
<PackageReference Include="MongoDB.Bson" Version="2.9.1" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
|
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
|
||||||
|
@ -6,20 +6,21 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Esyur.Core
|
namespace Esyur.Core
|
||||||
{
|
{
|
||||||
public class AsyncAwaiter<T> : INotifyCompletion
|
public class AsyncAwaiter : INotifyCompletion
|
||||||
{
|
{
|
||||||
Action callback = null;
|
Action callback = null;
|
||||||
|
|
||||||
AsyncException exception = null;
|
AsyncException exception = null;
|
||||||
|
|
||||||
T result;
|
object result;
|
||||||
|
|
||||||
|
|
||||||
public AsyncAwaiter(AsyncReply reply)
|
public AsyncAwaiter(AsyncReply reply)
|
||||||
{
|
{
|
||||||
reply.Then(x =>
|
reply.Then(x =>
|
||||||
{
|
{
|
||||||
this.IsCompleted = true;
|
this.IsCompleted = true;
|
||||||
this.result = (T)x;
|
this.result = x;
|
||||||
this.callback?.Invoke();
|
this.callback?.Invoke();
|
||||||
}).Error(x =>
|
}).Error(x =>
|
||||||
{
|
{
|
||||||
@ -29,7 +30,7 @@ namespace Esyur.Core
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetResult()
|
public object GetResult()
|
||||||
{
|
{
|
||||||
if (exception != null)
|
if (exception != null)
|
||||||
throw exception;
|
throw exception;
|
||||||
|
53
Esyur/Core/AsyncAwaiterGeneric.cs
Normal file
53
Esyur/Core/AsyncAwaiterGeneric.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Esyur.Core
|
||||||
|
{
|
||||||
|
public class AsyncAwaiter<T> : INotifyCompletion
|
||||||
|
{
|
||||||
|
Action callback = null;
|
||||||
|
|
||||||
|
AsyncException exception = null;
|
||||||
|
|
||||||
|
T result;
|
||||||
|
|
||||||
|
public AsyncAwaiter(AsyncReply<T> reply)
|
||||||
|
{
|
||||||
|
reply.Then(x =>
|
||||||
|
{
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.result = (T)x;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
}).Error(x =>
|
||||||
|
{
|
||||||
|
exception = x;
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetResult()
|
||||||
|
{
|
||||||
|
if (exception != null)
|
||||||
|
throw exception;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCompleted { get; private set; }
|
||||||
|
|
||||||
|
public void OnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
if (IsCompleted)
|
||||||
|
continuation?.Invoke();
|
||||||
|
else
|
||||||
|
// Continue....
|
||||||
|
callback = continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,9 +46,9 @@ namespace Esyur.Core
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new AsyncAwaiter<object[]> GetAwaiter()
|
public new AsyncBagAwaiter GetAwaiter()
|
||||||
{
|
{
|
||||||
return new AsyncAwaiter<object[]>(this);
|
return new AsyncBagAwaiter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public new object[] Wait()
|
public new object[] Wait()
|
||||||
|
53
Esyur/Core/AsyncBagAwaiter.cs
Normal file
53
Esyur/Core/AsyncBagAwaiter.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Esyur.Core
|
||||||
|
{
|
||||||
|
public class AsyncBagAwaiter : INotifyCompletion
|
||||||
|
{
|
||||||
|
Action callback = null;
|
||||||
|
|
||||||
|
AsyncException exception = null;
|
||||||
|
|
||||||
|
object[] result;
|
||||||
|
|
||||||
|
public AsyncBagAwaiter(AsyncBag reply)
|
||||||
|
{
|
||||||
|
reply.Then(x =>
|
||||||
|
{
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.result = x;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
}).Error(x =>
|
||||||
|
{
|
||||||
|
exception = x;
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] GetResult()
|
||||||
|
{
|
||||||
|
if (exception != null)
|
||||||
|
throw exception;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCompleted { get; private set; }
|
||||||
|
|
||||||
|
public void OnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
if (IsCompleted)
|
||||||
|
continuation?.Invoke();
|
||||||
|
else
|
||||||
|
// Continue....
|
||||||
|
callback = continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
53
Esyur/Core/AsyncBagAwaiterGeneric.cs
Normal file
53
Esyur/Core/AsyncBagAwaiterGeneric.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Esyur.Core
|
||||||
|
{
|
||||||
|
public class AsyncBagAwaiter<T> : INotifyCompletion
|
||||||
|
{
|
||||||
|
Action callback = null;
|
||||||
|
|
||||||
|
AsyncException exception = null;
|
||||||
|
|
||||||
|
T[] result;
|
||||||
|
|
||||||
|
public AsyncBagAwaiter(AsyncBag<T> reply)
|
||||||
|
{
|
||||||
|
reply.Then(x =>
|
||||||
|
{
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.result = x;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
}).Error(x =>
|
||||||
|
{
|
||||||
|
exception = x;
|
||||||
|
this.IsCompleted = true;
|
||||||
|
this.callback?.Invoke();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] GetResult()
|
||||||
|
{
|
||||||
|
if (exception != null)
|
||||||
|
throw exception;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCompleted { get; private set; }
|
||||||
|
|
||||||
|
public void OnCompleted(Action continuation)
|
||||||
|
{
|
||||||
|
if (IsCompleted)
|
||||||
|
continuation?.Invoke();
|
||||||
|
else
|
||||||
|
// Continue....
|
||||||
|
callback = continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,9 +51,9 @@ namespace Esyur.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public new AsyncAwaiter<T[]> GetAwaiter()
|
public new AsyncBagAwaiter<T> GetAwaiter()
|
||||||
{
|
{
|
||||||
return new AsyncAwaiter<T[]>(this);
|
return new AsyncBagAwaiter<T>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public new T[] Wait()
|
public new T[] Wait()
|
||||||
|
@ -255,9 +255,9 @@ namespace Esyur.Core
|
|||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncAwaiter<object> GetAwaiter()
|
public AsyncAwaiter GetAwaiter()
|
||||||
{
|
{
|
||||||
return new AsyncAwaiter<object>(this);
|
return new AsyncAwaiter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user