EventEmitter/EventEmitter.cs
/// <summary>
/// Whenever eventName is emitted, the methods attached to this event will be called
/// </summary>
/// <param name="eventNames">Event name to subscribe to</param>
/// <param name="method">Method to add to the event</param>
Whenever eventName is emitted, the methods attached to this event will be called
Whenever eventName is emitted the methods attached to this event will be called
public void On(string eventNames, Func<string, object?, Task> method)
        {
            _rwl.EnterWriteLock();
            var eventNameList = eventNames.Split(EventSeparator, StringSplitOptions.RemoveEmptyEntries);
            foreach (var eventName in eventNameList)
            {
                if (_events.TryGetValue(eventName, out var subscribedMethods))
                {
                    subscribedMethods.Add(method);
                }
                else
                {
                    _events.Add(eventName, new List<Func<string, object?, Task>> { method });
                }
            }
            _rwl.ExitWriteLock();
        }
public void On ( string eventNames , Func < string , object ? , Task > method ) { _rwl . EnterWriteLock ( ) ; var eventNameList = eventNames . Split ( EventSeparator , StringSplitOptions . RemoveEmptyEntries ) ; foreach ( var eventName in eventNameList ) { if ( _events . TryGetValue ( eventName , out var subscribedMethods ) ) { subscribedMethods . Add ( method ) ; } else { _events . Add ( eventName , new List < Func < string , object ? , Task > > { method } ) ; } } _rwl . ExitWriteLock ( ) ; }
Whenever eventName is emitted, the methods attached to this event will be called
Whenever eventName is emitted the methods attached to this event will be called
eventNames
string
Event name to subscribe to
Event name to subscribe to
method
Func<string, object?, Task>
Method to add to the event
Method to add to the event