private Task DownloadObjectAsyncImpl( RequestBuilder requestBuilder, Stream destination, DownloadObjectOptions options, CancellationToken cancellationToken, IProgress <IDownloadProgress> progress) => // Use Task.Run to prevent reporting progress synchronously in the original call. // We used to await Task.Yield(), but that doesn't actually achieve what we want. Task.Run(async() => { GaxPreconditions.CheckNotNull(destination, nameof(destination)); var downloader = CreateDownloader(options); options?.ModifyRequestBuilder(requestBuilder); string uri = requestBuilder.BuildUri().AbsoluteUri; if (progress != null) { downloader.ProgressChanged += progress.Report; progress.Report(InitialDownloadProgress.Instance); } var result = await downloader.DownloadAsync(uri, destination, cancellationToken).ConfigureAwait(false); if (result.Status == DownloadStatus.Failed) { throw result.Exception; } });
private void DownloadObjectImpl( RequestBuilder requestBuilder, Stream destination, DownloadObjectOptions options, IProgress <IDownloadProgress> progress) { // URI will definitely not be null; that's constructed internally. GaxPreconditions.CheckNotNull(destination, nameof(destination)); var downloader = CreateDownloader(options); options?.ModifyRequestBuilder(requestBuilder); string uri = requestBuilder.BuildUri().AbsoluteUri; if (progress != null) { downloader.ProgressChanged += progress.Report; progress.Report(InitialDownloadProgress.Instance); } var result = downloader.Download(uri, destination); if (result.Status == DownloadStatus.Failed) { throw result.Exception; } }