-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathEventEngineInterfaces.cs
57 lines (47 loc) · 1.73 KB
/
EventEngineInterfaces.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace PubnubApi.EventEngine.Core {
/// <summary>
/// Generic effect handler.
/// </summary>
internal interface IEffectHandler {
Task Cancel();
}
/// <summary>
/// Handler (implementation) for a given invocation. The invocation represents the input arguments of a handler.
/// </summary>
/// <typeparam name="T">Associated invocation</typeparam>
internal interface IEffectHandler<in T> : IEffectHandler where T : IEffectInvocation {
Task Run(T invocation);
bool IsBackground(T invocation);
}
/// <summary>
/// An effect invocation. It represents calling <c>Run()</c> on a registered effect handler - calling it is orchestrated by the dispatcher.
/// </summary>
internal interface IEffectInvocation { }
/// <summary>
/// A cancel effect invocation. It represents calling <c>Cancel()</c> on a registered effect handler - calling it is orchestrated by the dispatcher.
/// </summary>
internal interface IEffectCancelInvocation : IEffectInvocation { }
internal interface IEvent { };
internal abstract class State
{
public virtual IEnumerable<IEffectInvocation> OnEntry { get; } = null;
public virtual IEnumerable<IEffectInvocation> OnExit { get; } = null;
/// <summary>
/// The EE transition pure function.
/// </summary>
/// <param name="e">Input event</param>
/// <returns>Target state and invocation list, or null for no-transition</returns>
public abstract TransitionResult Transition(IEvent e);
public TransitionResult With(params IEffectInvocation[] invocations)
{
return new TransitionResult(this, invocations);
}
public static implicit operator TransitionResult(State s)
{
return new TransitionResult(s);
}
}
}