public async Task <IReadOnlyCollection <ObjectInfo> > GetOrdered(string?fromName, CancellationToken cancellationToken) { var retries = _retries; while (true) { try { return(await _inner.GetOrdered(fromName, cancellationToken)); } catch (OperationCanceledException) { throw; } catch (TimeoutException) { } #pragma warning disable CA1031 // Do not catch general exception types -- dumb retry mechanism catch when(retries-- > 0) #pragma warning restore CA1031 // Do not catch general exception types { } await Task.Delay(1511, cancellationToken); } }
public async Task Populate(CancellationToken cancellationToken) { if (_infos is null) { return; } ObjectInfo?lastInfo = _infos.LastOrDefault(); _infos.RemoveRange(0, _skip); _skip = 0; if (_infos.Count >= MaxListLength) { return; } var task = Interlocked.Exchange(ref _nextTask, null) ?? _source.GetOrdered(LastName, cancellationToken); var newInfos = await task; var index = 0; foreach (var info in newInfos) { if (info.CompareTo(lastInfo) <= 0) { throw new InvalidDataException(FormattableString.Invariant( $"Current object info {info} at index {index} is not sorted wrt {lastInfo}, last name \"{LastName}\", source {_source}.")); } _infos.Add(info); lastInfo = info; ++index; } var count = _infos.Count; if (count == 0) { _infos = null; LastName = null; _nextTask = null; return; } LastName = _infos[count - 1].Name; _nextTask = _source.GetOrdered(LastName, cancellationToken); }
public async Task <IReadOnlyCollection <ObjectInfo> > GetOrdered(string?fromName, CancellationToken cancellationToken) { var lockTask = _locker.Lock(cancellationToken); var getTask = _source.GetOrdered(fromName, cancellationToken); await Task.WhenAll(lockTask, getTask); return(getTask.Result); }
public async Task <IReadOnlyCollection <ObjectInfo> > GetOrdered(string?fromName, CancellationToken cancellationToken) { IReadOnlyCollection <ObjectInfo> result; try { result = await _inner.GetOrdered(fromName, cancellationToken); } catch (OperationCanceledException) { throw; } catch { _writer.Add(_prefix + "get_errors", 1); throw; } _writer.Add(_prefix + "gets", 1); _writer.Add(_prefix + "objects", result.Count); return(result); }
public Task <IReadOnlyCollection <ObjectInfo> > GetOrdered(string?fromName, CancellationToken cancellationToken) => _source.GetOrdered(fromName, cancellationToken);