Beispiel #1
0
            public async override Task Subscribe(PriceUpdateSubscription request, IServerStreamWriter <PriceUpdate> responseStream, ServerCallContext context)
            {
                var data = CreateUpdateMessage(1);

                try
                {
                    var cancel = context.CancellationToken;
                    while (!cancel.IsCancellationRequested)
                    {
                        await responseStream.WriteAsync(data);
                    }
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }
Beispiel #2
0
 public async override Task Subscribe(PriceUpdateSubscription request, IServerStreamWriter <PriceUpdate> responseStream, ServerCallContext context)
 {
     try
     {
         var cancel = context.CancellationToken;
         var buffer = new BufferBlock <PriceUpdate>(
             new DataflowBlockOptions {
             BoundedCapacity = 1
         });
         var consumer = SendUpdates(buffer, responseStream, cancel);
         var producer = ReceiveUpdates(request, buffer, cancel);
         await Task.WhenAll(producer, consumer);
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex);
         throw;
     }
 }
Beispiel #3
0
 private async Task ReceiveUpdates(PriceUpdateSubscription request, ITargetBlock <PriceUpdate> output, CancellationToken cancel)
 {
     try
     {
         var httpRequest  = m_client.Subscribe(request);
         var subscription = httpRequest.ResponseStream;
         while (await subscription.MoveNext(cancel))
         {
             var data = subscription.Current;
             await output.SendAsync(data, cancel);
         }
         throw new RpcException(httpRequest.GetStatus());
     }
     catch (Exception ex)
     {
         Console.Error.WriteLine(ex);
         throw;
     }
 }