-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add abstract UpdateStatus methods to OperationResult (#45475)
* Add abstract UpdateStatus methods to OperationResult * refdocs; refactor; CHANGELOG * Add tests * add test for Retry-After header value * fix lower bound and shorten Retry-After test time * rename IsCompleted -> HasCompleted; make non-abstract * remove CT extension in favor of internal factory method on RequestOptions
- Loading branch information
1 parent
8d1e831
commit 94a3d32
Showing
12 changed files
with
396 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
sdk/core/System.ClientModel/src/Internal/PollingInterval.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.ClientModel.Primitives; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.ClientModel.Internal; | ||
|
||
internal sealed class PollingInterval | ||
{ | ||
private static readonly TimeSpan DefaultDelay = TimeSpan.FromSeconds(1.0); | ||
|
||
private readonly TimeSpan _interval; | ||
|
||
public PollingInterval(TimeSpan? interval = default) | ||
{ | ||
_interval = interval ?? DefaultDelay; | ||
} | ||
|
||
public async Task WaitAsync(PipelineResponse response, CancellationToken cancellationToken) | ||
{ | ||
TimeSpan delay = GetDelay(response); | ||
|
||
await Task.Delay(delay, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
public void Wait(PipelineResponse response, CancellationToken cancellationToken) | ||
{ | ||
TimeSpan delay = GetDelay(response); | ||
|
||
if (!cancellationToken.CanBeCanceled) | ||
{ | ||
Thread.Sleep(delay); | ||
return; | ||
} | ||
|
||
if (cancellationToken.WaitHandle.WaitOne(delay)) | ||
{ | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
} | ||
} | ||
|
||
private TimeSpan GetDelay(PipelineResponse response) | ||
=> PipelineResponseHeaders.TryGetRetryAfter(response, out TimeSpan retryAfter) | ||
&& retryAfter > _interval ? retryAfter : _interval; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.