internal Task DeliverItem(StreamId streamId, object item, bool fireAndForgetDelivery, bool optimizeForImmutableData) { var tasks = fireAndForgetDelivery ? null : new List <Task>(); foreach (KeyValuePair <GuidId, Tuple <IStreamConsumerExtension, IStreamFilterPredicateWrapper> > subscriptionKvp in consumers) { IStreamConsumerExtension remoteConsumer = subscriptionKvp.Value.Item1; // Apply filter(s) to see if we should forward this item to this consumer IStreamFilterPredicateWrapper filter = subscriptionKvp.Value.Item2; if (filter != null) { if (!filter.ShouldReceive(streamId, filter.FilterData, item)) { continue; } } Task task = DeliverToRemote(remoteConsumer, streamId, subscriptionKvp.Key, item, optimizeForImmutableData); if (fireAndForgetDelivery) { task.Ignore(); } else { tasks.Add(task); } } // If there's no subscriber, presumably we just drop the item on the floor return(fireAndForgetDelivery ? TaskDone.Done : Task.WhenAll(tasks)); }
private Task NextItem(object item, StreamSequenceToken token) { T typedItem; try { typedItem = (T)item; } catch (InvalidCastException) { // We got an illegal item on the stream -- close it with a Cast exception throw new InvalidCastException("Received an item of type " + item.GetType().Name + ", expected " + typeof(T).FullName); } // This method could potentially be invoked after Dispose() has been called, // so we have to ignore the request or we risk breaking unit tests AQ_01 - AQ_04. if (observer == null || !IsValid) { return(TaskDone.Done); } if (filterWrapper != null && !filterWrapper.ShouldReceive(streamImpl, filterWrapper.FilterData, typedItem)) { return(TaskDone.Done); } return(observer.OnNextAsync(typedItem, token)); }
internal Task DeliverItem(StreamId streamId, object item, bool fireAndForgetDelivery) { var tasks = fireAndForgetDelivery ? null : new List <Task>(); var immutableItem = new Immutable <object>(item); foreach (Guid key in consumers.Keys) { var data = consumers[key]; IStreamConsumerExtension remoteConsumer = data.Item1; // Apply filter(s) to see if we should forward this item to this consumer IStreamFilterPredicateWrapper filter = data.Item2; if (filter != null) { if (!filter.ShouldReceive(streamId, filter.FilterData, item)) { continue; } } Task task = remoteConsumer.DeliverItem(streamId, immutableItem, null); if (fireAndForgetDelivery) { task.Ignore(); } else { tasks.Add(task); } } // If there's no subscriber, presumably we just drop the item on the floor return(fireAndForgetDelivery ? TaskDone.Done : Task.WhenAll(tasks)); }
public Task OnNextAsync(T item, StreamSequenceToken token) { // This method could potentially be invoked after Dispose() has been called, // so we have to ignore the request or we risk breaking unit tests AQ_01 - AQ_04. if (observer == null) { return(TaskDone.Done); } if (filterWrapper != null && !filterWrapper.ShouldReceive(streamImpl, FilterData, item)) { return(TaskDone.Done); } return(observer.OnNextAsync(item, token)); }
private Task NextItem(T item, StreamSequenceToken token) { // This method could potentially be invoked after Dispose() has been called, // so we have to ignore the request or we risk breaking unit tests AQ_01 - AQ_04. if (this.observer == null || !IsValid) { return(Task.CompletedTask); } if (filterWrapper != null && !filterWrapper.ShouldReceive(streamImpl, filterWrapper.FilterData, item)) { return(Task.CompletedTask); } return(this.observer.OnNextAsync(item, token)); }