示例#1
0
 private void PassivePullRumors(object sender, PullRumorEventArgs e)
 {
     semaphore.Protect(() =>
     {
         e.Rumors = pullStateRumorCounterDictionary
                    .Select(p => new Rumor
         {
             Counter = p.Value,
             Payload = p.Key
         });
     });
 }
示例#2
0
        public override async Task Pull(
            PullRequest request,
            IServerStreamWriter <Rumor> responseStream,
            ServerCallContext context)
        {
            var pullEventArgs = new PullRumorEventArgs();

            OnPull?.Invoke(this, pullEventArgs);

            if (pullEventArgs.Rumors != null)
            {
                using (var rumorsAsyncEnumerator = pullEventArgs.Rumors.GetEnumerator())
                {
                    while (!context.CancellationToken.IsCancellationRequested &&
                           rumorsAsyncEnumerator.MoveNext())
                    {
                        await responseStream.WriteAsync(rumorsAsyncEnumerator.Current);
                    }
                }
            }
        }