Perform Control Transfer With Retry
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
public static Task<T> PerformControlTransferWithRetry<T>( | |
this IUsbDevice usbDevice, | |
Func<IUsbDevice, Task<T>> func, | |
int retryCount = 3, | |
int sleepDurationMilliseconds = 250) | |
{ | |
var retryPolicy = Policy | |
.Handle<ApiException>() | |
.Or<ControlTransferException>() | |
.WaitAndRetryAsync( | |
retryCount, | |
i => TimeSpan.FromMilliseconds(sleepDurationMilliseconds), | |
onRetryAsync: (e, t) => usbDevice.ClearStatusAsync() | |
); | |
return retryPolicy.ExecuteAsync(() => func(usbDevice)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment