File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,19 @@ public void Process(IEvent e)
1616 }
1717
1818 protected abstract void Process ( T e ) ;
19+ }
20+
21+ public class SimpleProcessor < T > : EventProcessor < T > where T : IEvent
22+ {
23+ private readonly Action < T > processor ;
24+
25+ public SimpleProcessor ( Action < T > processor )
26+ {
27+ this . processor = processor ;
28+ }
29+
30+ protected override void Process ( T e )
31+ {
32+ processor ( e ) ;
33+ }
1934}
Original file line number Diff line number Diff line change @@ -58,14 +58,14 @@ public void Close()
5858 this . network . Disconnect ( ) ;
5959 }
6060
61- public Session AddEventProcessor < T > ( ) where T : IEventProcessor
61+ public Session AddProcessor < T > ( ) where T : IEventProcessor
6262 {
6363 var processor = Activator . CreateInstance < T > ( ) ;
64- AddEventProcessor ( processor ) ;
64+ AddProcessor ( processor ) ;
6565 return this ;
6666 }
6767
68- public void AddEventProcessor < T > ( T processor ) where T : IEventProcessor
68+ public void AddProcessor < T > ( T processor ) where T : IEventProcessor
6969 {
7070 var eventProcessors = processors . GetValueOrDefault ( processor . EventType ) ;
7171 if ( eventProcessors is null )
@@ -76,6 +76,11 @@ public void AddEventProcessor<T>(T processor) where T : IEventProcessor
7676 eventProcessors . Add ( processor ) ;
7777 }
7878
79+ public void AddProcessor < T > ( Action < T > task ) where T : IEvent
80+ {
81+ AddProcessor ( new SimpleProcessor < T > ( task ) ) ;
82+ }
83+
7984 public void Emit < T > ( T e ) where T : IEvent
8085 {
8186 var eventProcessors = processors . GetValueOrDefault ( e . GetType ( ) ) ;
You can’t perform that action at this time.
0 commit comments