Skip to content

Commit 57f4fb2

Browse files
committed
wip: preliminary potential fix for dispatcher
1 parent 206713b commit 57f4fb2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Api/PubnubApi/EventEngine/Core/EffectDispatcher.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class EffectDispatcher {
1313
/// <summary>
1414
/// Dispatch an invocation i.e. call a registered effect handler.
1515
/// </summary>
16-
public async Task Dispatch<T>(T invocation) where T : IEffectInvocation {
16+
public async Task Dispatch(IEffectInvocation invocation) {
1717
if (!effectInvocationHandlerMap.ContainsKey(invocation.GetType())) {
1818
throw new ArgumentException($"No handler for {invocation.GetType().Name} found.");
1919
}
@@ -24,7 +24,7 @@ public async Task Dispatch<T>(T invocation) where T : IEffectInvocation {
2424
await effectInvocationHandlerMap[invocation.GetType()].Cancel();
2525
} else
2626
{
27-
var handler = ((IEffectHandler<T>)effectInvocationHandlerMap[invocation.GetType()]);
27+
var handler = effectInvocationHandlerMap[invocation.GetType()];
2828
if (handler.IsBackground(invocation))
2929
handler.Run(invocation).Start();
3030
else

src/Api/PubnubApi/EventEngine/Core/Utils.cs

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Threading.Tasks;
33
using System.Collections.Generic;
4+
using System.Reflection;
45

56
namespace PubnubApi.EventEngine.Core
67
{
@@ -17,6 +18,20 @@ internal static IEffectInvocation[] AsArray(this IEffectInvocation invocation)
1718
{
1819
return new IEffectInvocation[] { invocation };
1920
}
21+
22+
internal static bool IsBackground(this IEffectHandler handler, IEffectInvocation invocation)
23+
{
24+
return (bool)handler.GetType()
25+
.GetMethod("IsBackground")
26+
.Invoke(handler, new object[] { invocation });
27+
}
28+
29+
internal static Task Run(this IEffectHandler handler, IEffectInvocation invocation)
30+
{
31+
return (Task)handler.GetType()
32+
.GetMethod("Run")
33+
.Invoke(handler, new object[] { invocation });
34+
}
2035
}
2136

2237
public class TransitionResult

0 commit comments

Comments
 (0)