Exemple #1
0
        public override async Task Fib(FibArgs request, IServerStreamWriter <Num> responseStream, ServerCallContext context)
        {
            var limit         = request.Limit > 0 ? request.Limit : long.MaxValue;
            var fibEnumerator = FibInternal(limit).GetEnumerator();

            // Keep streaming the sequence until the call is cancelled.
            // Use CancellationToken from ServerCallContext to detect the cancellation.
            while (!context.CancellationToken.IsCancellationRequested && fibEnumerator.MoveNext())
            {
                await responseStream.WriteAsync(fibEnumerator.Current);

                await Task.Delay(100);
            }
        }
Exemple #2
0
        public async Task Fib(FibArgs request, IServerStreamWriter <Num> responseStream, ServerCallContext context)
        {
            if (request.Limit <= 0)
            {
                // keep streaming the sequence until cancelled.
                IEnumerator <Num> fibEnumerator = FibInternal(long.MaxValue).GetEnumerator();
                while (!context.CancellationToken.IsCancellationRequested && fibEnumerator.MoveNext())
                {
                    await responseStream.WriteAsync(fibEnumerator.Current);

                    await Task.Delay(100);
                }
            }

            if (request.Limit > 0)
            {
                foreach (var num in FibInternal(request.Limit))
                {
                    await responseStream.WriteAsync(num);
                }
            }
        }