示例#1
0
        private async Task ReadAsync()
        {
            var ct = _cts.Token;

            while (true)
            {
                // Start watch now, so no watch events are missed
                var  delay     = _pollInterval + _maxJitter * (_rnd.NextDouble() - 0.5);
                Task watchTask = _enableWatch ? _reader.AwaitChange(delay, ct) : _taskHelper.Delay(delay, ct);
                // Read as much as is available
                var en = (await _reader.ReadAsync((int)Count, ct: ct).ConfigureAwait(_taskHelper)).GetEnumerator();
                while (await en.MoveNext(ct).ConfigureAwait(_taskHelper))
                {
                    Add(en.Current);
                }
                _tcs.TrySetResult(0);
                // Schedule/wait-for next read
                await watchTask.ConfigureAwait(_taskHelper);
            }
        }