public async Task <TResult> Invoke <TResult>(Func <IAmazonS3, CancellationToken, Task <TResult> > action, CancellationToken cancellationToken) { if (_timeout != Timeout.InfiniteTimeSpan) { using var cts = new CancellationTokenSource(_timeout); using var combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cts.Token); return(await _inner.Invoke(action, combinedCts.Token)); } return(await _inner.Invoke(action, cancellationToken)); }
public async Task <TResult> Invoke <TResult>(Func <IAmazonS3, CancellationToken, Task <TResult> > action, CancellationToken cancellationToken) { try { return(await _inner.Invoke(action, cancellationToken)); } catch (OperationCanceledException exception) when(!cancellationToken.IsCancellationRequested) { throw new TimeoutException("S3 operation timed out.", exception); } }
public async Task <TResult> Invoke <TResult>(Func <IAmazonS3, CancellationToken, Task <TResult> > action, CancellationToken cancellationToken) { try { return(await _inner.Invoke(action, cancellationToken)); } catch (AmazonServiceException exception) when(exception.InnerException is WebException webException && webException.Status == WebExceptionStatus.RequestCanceled) { throw new OperationCanceledException("Amazon service exception treated as request cancellation.", exception); } catch (AmazonS3Exception exception) when(exception.StatusCode == HttpStatusCode.ServiceUnavailable) { throw new OperationCanceledException("S3 \"service unavailable\" exception treated as request cancellation.", exception); } }