private void PassivePullRumors(object sender, PullRumorEventArgs e) { semaphore.Protect(() => { e.Rumors = pullStateRumorCounterDictionary .Select(p => new Rumor { Counter = p.Value, Payload = p.Key }); }); }
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); } } } }