Esempio n. 1
0
        /// <summary>
        /// Forces this listener to raise the given event. May not be invocable by all listeners.
        /// </summary>
        /// <param name="eventData">The event data.</param>
        /// <returns>Task.</returns>
        public async Task RaiseEvent(SubscriptionEvent eventData)
        {
            Validation.ThrowIfNull(eventData, nameof(eventData));

            _logger?.SubscriptionEventReceived(eventData);
            var tasks = new List <Task>();

            lock (_receivers)
            {
                if (_receivers.Count > 0)
                {
                    var eventName = eventData.ToSubscriptionEventName();
                    if (!_receivers.ContainsKey(eventName))
                    {
                        return;
                    }

                    foreach (var receiver in _receivers[eventName])
                    {
                        var task = receiver.ReceiveEvent(eventData);
                        tasks.Add(task);
                    }
                }
            }

            await Task.WhenAll(tasks);
        }
 /// <summary>
 /// Raises a new event in a manner such that a compatible <see cref="ISubscriptionEventRouter" /> could
 /// receive it for processing.
 /// </summary>
 /// <param name="eventData">The event to publish.</param>
 /// <returns>Task.</returns>
 public Task PublishEvent(SubscriptionEvent eventData)
 {
     // this publisher pushes events raised
     // by mutations and queries directly into the DI-configured router
     // for immediate dispatch within this instance
     return(_eventRouter.RaiseEvent(eventData));
 }