move godot events to wrapper
This commit is contained in:
@@ -14,59 +14,3 @@ public class GlobalEvents
|
||||
public EventWrapper<SharpIdeProjectModel, Task> ProjectStoppedRunning { get; private set; } = new(_ => Task.CompletedTask);
|
||||
public EventWrapper<ExecutionStopInfo, Task> DebuggerExecutionStopped { get; private set; } = new(_ => Task.CompletedTask);
|
||||
}
|
||||
|
||||
public static class AsyncEventExtensions
|
||||
{
|
||||
public static void InvokeParallelFireAndForget(this MulticastDelegate @event) => FireAndForget(() => @event.InvokeParallelAsync());
|
||||
public static void InvokeParallelFireAndForget<T>(this MulticastDelegate @event, T arg) => FireAndForget(() => @event.InvokeParallelAsync(arg));
|
||||
public static void InvokeParallelFireAndForget<T, U>(this MulticastDelegate @event, T arg, U arg2) => FireAndForget(() => @event.InvokeParallelAsync(arg, arg2));
|
||||
|
||||
private static async void FireAndForget(Func<Task> action)
|
||||
{
|
||||
try
|
||||
{
|
||||
await action().ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"An exception occurred in an event handler: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
public static Task InvokeParallelAsync(this MulticastDelegate @event)
|
||||
{
|
||||
return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func<Task>)del)());
|
||||
}
|
||||
|
||||
public static Task InvokeParallelAsync<T>(this MulticastDelegate @event, T arg)
|
||||
{
|
||||
return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func<T, Task>)del)(arg));
|
||||
}
|
||||
public static Task InvokeParallelAsync<T, U>(this MulticastDelegate @event, T arg, U arg2)
|
||||
{
|
||||
return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func<T, U, Task>)del)(arg, arg2));
|
||||
}
|
||||
|
||||
private static async Task InvokeDelegatesAsync(IEnumerable<Delegate> invocationList, Func<Delegate, Task> delegateExecutorDelegate)
|
||||
{
|
||||
var tasks = invocationList.Select(async del =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await delegateExecutorDelegate(del).ConfigureAwait(false);
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex;
|
||||
}
|
||||
});
|
||||
|
||||
var results = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
var exceptions = results.Where(r => r is not null).Select(r => r!).ToList();
|
||||
if (exceptions.Count != 0)
|
||||
{
|
||||
throw new AggregateException(exceptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user