Let you invoke async on the game thread, just not async blocking.
Fixed event list
This commit is contained in:
@@ -75,11 +75,6 @@ namespace Torch.Event
|
|||||||
removeCount++;
|
removeCount++;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
if (removeCount > 0)
|
|
||||||
{
|
|
||||||
_dispatchersDirty = true;
|
|
||||||
_dispatchers.RemoveRange(_dispatchers.Count - removeCount, removeCount);
|
|
||||||
}
|
|
||||||
return removeCount;
|
return removeCount;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@@ -231,6 +231,14 @@ namespace Torch
|
|||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
public void InvokeBlocking(Action action, int timeoutMs = -1, [CallerMemberName] string caller = "")
|
public void InvokeBlocking(Action action, int timeoutMs = -1, [CallerMemberName] string caller = "")
|
||||||
{
|
{
|
||||||
|
if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread)
|
||||||
|
{
|
||||||
|
Debug.Assert(false, $"{nameof(InvokeBlocking)} should not be called on the game thread.");
|
||||||
|
// ReSharper disable once HeuristicUnreachableCode
|
||||||
|
action.Invoke();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// ReSharper disable once ExplicitCallerInfoArgument
|
// ReSharper disable once ExplicitCallerInfoArgument
|
||||||
Task task = InvokeAsync(action, caller);
|
Task task = InvokeAsync(action, caller);
|
||||||
if (!task.Wait(timeoutMs))
|
if (!task.Wait(timeoutMs))
|
||||||
@@ -243,19 +251,6 @@ namespace Torch
|
|||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
public Task<T> InvokeAsync<T>(Func<T> action, [CallerMemberName] string caller = "")
|
public Task<T> InvokeAsync<T>(Func<T> action, [CallerMemberName] string caller = "")
|
||||||
{
|
{
|
||||||
if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread)
|
|
||||||
{
|
|
||||||
Debug.Assert(false, $"{nameof(InvokeAsync)} should not be called on the game thread.");
|
|
||||||
// ReSharper disable once HeuristicUnreachableCode
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return Task.FromResult(action.Invoke());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return Task.FromException<T>(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var ctx = new TaskCompletionSource<T>();
|
var ctx = new TaskCompletionSource<T>();
|
||||||
MySandboxGame.Static.Invoke(() =>
|
MySandboxGame.Static.Invoke(() =>
|
||||||
{
|
{
|
||||||
@@ -273,28 +268,12 @@ namespace Torch
|
|||||||
}
|
}
|
||||||
}, caller);
|
}, caller);
|
||||||
return ctx.Task;
|
return ctx.Task;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
public Task InvokeAsync(Action action, [CallerMemberName] string caller = "")
|
public Task InvokeAsync(Action action, [CallerMemberName] string caller = "")
|
||||||
{
|
{
|
||||||
if (Thread.CurrentThread == MySandboxGame.Static.UpdateThread)
|
|
||||||
{
|
|
||||||
Debug.Assert(false, $"{nameof(InvokeAsync)} should not be called on the game thread.");
|
|
||||||
// ReSharper disable once HeuristicUnreachableCode
|
|
||||||
try
|
|
||||||
{
|
|
||||||
action.Invoke();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
return Task.FromException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var ctx = new TaskCompletionSource<bool>();
|
var ctx = new TaskCompletionSource<bool>();
|
||||||
MySandboxGame.Static.Invoke(() =>
|
MySandboxGame.Static.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user