2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2020-03-25 08:52:15 +03:00
parent 8bd9b3282c
commit 836a1fdeae
23 changed files with 466 additions and 216 deletions

View File

@ -56,6 +56,10 @@ namespace Esyur.Core
return (object[])base.Wait();
}
public new object[] Wait(int timeout)
{
return (object[])base.Wait(timeout);
}
public void Seal()
{

View File

@ -28,13 +28,18 @@ using System.Text;
namespace Esyur.Core
{
public class AsyncException: Exception
public class AsyncException : Exception
{
public readonly ErrorType Type;
public readonly ExceptionCode Code;
public AsyncException(Exception exception) :base(exception.Message, exception)
{
Type = ErrorType.Exception;
Code = 0;
}
public override string StackTrace => InnerException != null && Type == ErrorType.Exception ? InnerException.StackTrace : base.StackTrace;
public AsyncException(ErrorType type, ushort code, string message)
: base(type == ErrorType.Management ? ((ExceptionCode)code).ToString() : message)

View File

@ -89,6 +89,27 @@ namespace Esyur.Core
}
public object Wait(int millisecondsTimeout)
{
if (resultReady)
return result;
if (Debug)
Console.WriteLine($"AsyncReply: {Id} Wait");
if (!mutex.WaitOne(millisecondsTimeout))
{
var e = new Exception("AsyncReply timeout");
TriggerError(e);
throw e;
}
if (Debug)
Console.WriteLine($"AsyncReply: {Id} Wait ended");
return result;
}
public object Result
{
get { return result; }
@ -210,9 +231,9 @@ namespace Esyur.Core
if (exception is AsyncException)
this.exception = exception as AsyncException;
else
this.exception = new AsyncException(ErrorType.Management, 0, exception.Message);
this.exception = new AsyncException(exception);
// lock (callbacksLock)
// {
foreach (var cb in errorCallbacks)

View File

@ -79,6 +79,12 @@ namespace Esyur.Core
{
return (T)base.Wait();
}
public new T Wait(int millisecondsTimeout)
{
return (T)base.Wait(millisecondsTimeout);
}
/*
protected new List<Action> callbacks = new List<Action>();
protected new object result;