Task Init(CancellationToken cancellation) { StreamPubSubWrapper.Hook(services, providers, stream => StreamSubscriptionSpecification .Match(system, stream.Id, subscriptions.Find(stream.Provider)) .Select(x => new StreamPubSubMatch(x.Receive)) .ToArray()); return(Task.CompletedTask); }
public IAsyncStream <T> GetStream <T>(Guid unused, string id) { var stream = provider.GetStream <T>(unused, id); return((IAsyncStream <T>)streams.GetValue(stream, _ => { var recipients = StreamSubscriptionSpecification.Match(system, id, specifications); Func <T, Task> fan = item => Task.CompletedTask; Func <IEnumerable <T>, Task> batchFan = batch => Task.CompletedTask; if (recipients.Length > 0) { fan = item => Task.WhenAll(recipients.Select(x => x.Receive(item))); batchFan = batch => Task.WhenAll(recipients.Select(x => x.Receive(batch))); } return new StreamVentilator <T>(stream, fan, batchFan); })); }