Commit 2b16da45 authored by Marc Gravell's avatar Marc Gravell

fix #934 - try to avoid exposing AggregateException unnecessarily

parent 16c50456
......@@ -566,8 +566,15 @@ internal bool TryResend(int hashSlot, Message message, EndPoint endpoint, bool i
public void Wait(Task task)
{
if (task == null) throw new ArgumentNullException(nameof(task));
try
{
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException();
}
catch (AggregateException aex) when (IsSingle(aex))
{
throw aex.InnerExceptions[0];
}
}
/// <summary>
/// Wait for a given asynchronous operation to complete (or timeout)
......@@ -577,10 +584,23 @@ public void Wait(Task task)
public T Wait<T>(Task<T> task)
{
if (task == null) throw new ArgumentNullException(nameof(task));
try
{
if (!task.Wait(TimeoutMilliseconds)) throw new TimeoutException();
}
catch (AggregateException aex) when (IsSingle(aex))
{
throw aex.InnerExceptions[0];
}
return task.Result;
}
private static bool IsSingle(AggregateException aex)
{
try { return aex != null && aex.InnerExceptions.Count == 1; }
catch { return false; }
}
/// <summary>
/// Wait for the given asynchronous operations to complete (or timeout)
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment