为TaskAwaiter传入异常参数方便处理异常

This commit is contained in:
milimoe 2023-09-08 19:18:59 +08:00
parent 1c4e796f09
commit e4aef07792
Signed by: milimoe
GPG Key ID: 05D280912DA6C69E
3 changed files with 6 additions and 6 deletions

View File

@ -6,6 +6,6 @@
public Exception Exception { get; } public Exception Exception { get; }
public ITaskAwaiter OnCompleted(Action action); public ITaskAwaiter OnCompleted(Action action);
public ITaskAwaiter OnError(Action action); public ITaskAwaiter OnError(Action<Exception> action);
} }
} }

View File

@ -50,7 +50,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action"></param>
/// <returns></returns> /// <returns></returns>
public TaskAwaiter OnError(Action action) public TaskAwaiter OnError(Action<System.Exception> action)
{ {
awaiter = awaiter.OnError(action); awaiter = awaiter.OnError(action);
return this; return this;

View File

@ -27,7 +27,7 @@ namespace Milimoe.FunGame.Core.Service
public Exception Exception => _Exception; public Exception Exception => _Exception;
private delegate void CompletedEvent(); private delegate void CompletedEvent();
private delegate void ErrorEvent(); private delegate void ErrorEvent(Exception e);
private event CompletedEvent? Completed; private event CompletedEvent? Completed;
private event ErrorEvent? Error; private event ErrorEvent? Error;
@ -57,7 +57,7 @@ namespace Milimoe.FunGame.Core.Service
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action"></param>
/// <returns></returns> /// <returns></returns>
public ITaskAwaiter OnError(Action action) public ITaskAwaiter OnError(Action<Exception> action)
{ {
Error += new ErrorEvent(action); Error += new ErrorEvent(action);
return this; return this;
@ -74,7 +74,7 @@ namespace Milimoe.FunGame.Core.Service
catch (Exception e) catch (Exception e)
{ {
_Exception = e; _Exception = e;
Error?.Invoke(); Error?.Invoke(e);
} }
} }
@ -89,7 +89,7 @@ namespace Milimoe.FunGame.Core.Service
catch (Exception e) catch (Exception e)
{ {
_Exception = e; _Exception = e;
Error?.Invoke(); Error?.Invoke(e);
} }
} }
} }