public Task SubscribeToAllStreams(Action <RecordedEvent> eventAppeared, Action subscriptionDropped) { var id = Guid.NewGuid(); var source = new TaskCompletionSource <object>(); if (_subscriptions.TryAdd(id, new Subscription(source, id, eventAppeared, subscriptionDropped))) { var subscribe = new ClientMessages.SubscribeToAllStreams(); var pkg = new TcpPackage(TcpCommand.SubscribeToAllStreams, id, subscribe.Serialize()); _connection.EnqueueSend(pkg.AsByteArray()); } else { source.SetException(new Exception("Failed to add subscription to all streams. Concurrency failure")); } return(source.Task); }
public Task SubscribeToAllStreams(Action<RecordedEvent> eventAppeared, Action subscriptionDropped) { var id = Guid.NewGuid(); var source = new TaskCompletionSource<object>(); if (_subscriptions.TryAdd(id, new Subscription(source, id, eventAppeared, subscriptionDropped))) { var subscribe = new ClientMessages.SubscribeToAllStreams(); var pkg = new TcpPackage(TcpCommand.SubscribeToAllStreams, id, subscribe.Serialize()); _connection.EnqueueSend(pkg.AsByteArray()); } else { source.SetException(new Exception("Failed to add subscription to all streams. Concurrency failure")); } return source.Task; }