11namespace Ydb . Sdk . Ado . RetryPolicy ;
22
3- internal class YdbRetryPolicyExecutor
3+ internal sealed class YdbRetryPolicyExecutor
44{
5- private readonly YdbRetryPolicy _retryPolicy ;
5+ private readonly IRetryPolicy _retryPolicy ;
66
7- public YdbRetryPolicyExecutor ( YdbRetryPolicy retryPolicy )
7+ public YdbRetryPolicyExecutor ( IRetryPolicy retryPolicy )
88 {
99 _retryPolicy = retryPolicy ;
1010 }
@@ -25,15 +25,19 @@ public YdbRetryPolicyExecutor(YdbRetryPolicy retryPolicy)
2525 /// first time or after retrying transient failures). If the task fails with a non-transient error or
2626 /// the retry limit is reached, the returned task will become faulted and the exception must be observed.
2727 /// </returns>
28- public virtual Task < TResult > ExecuteAsync < TResult > ( Func < CancellationToken , Task < TResult > > operation ,
29- CancellationToken cancellationToken = default ) => ExecuteImplementationAsync ( operation , cancellationToken ) ;
28+ public Task < TResult > ExecuteAsync < TResult > (
29+ Func < CancellationToken , Task < TResult > > operation ,
30+ CancellationToken cancellationToken = default
31+ ) => ExecuteImplementationAsync ( operation , cancellationToken ) ;
3032
31- public async Task ExecuteAsync ( Func < CancellationToken , Task > operation , CancellationToken cancellationToken = new ( ) )
32- => await ExecuteImplementationAsync ( async ct =>
33- {
34- await operation ( ct ) . ConfigureAwait ( false ) ;
35- return 0 ;
36- } , cancellationToken ) . ConfigureAwait ( false ) ;
33+ public async Task ExecuteAsync (
34+ Func < CancellationToken , Task > operation ,
35+ CancellationToken cancellationToken = default
36+ ) => await ExecuteImplementationAsync ( async ct =>
37+ {
38+ await operation ( ct ) . ConfigureAwait ( false ) ;
39+ return 0 ;
40+ } , cancellationToken ) . ConfigureAwait ( false ) ;
3741
3842 private async Task < TResult > ExecuteImplementationAsync < TResult > (
3943 Func < CancellationToken , Task < TResult > > operation ,
@@ -44,7 +48,7 @@ CancellationToken cancellationToken
4448 while ( true )
4549 {
4650 cancellationToken . ThrowIfCancellationRequested ( ) ;
47-
51+
4852 try
4953 {
5054 return await operation ( cancellationToken ) . ConfigureAwait ( false ) ;
@@ -54,7 +58,7 @@ CancellationToken cancellationToken
5458 var delay = _retryPolicy . GetNextDelay ( e , attempt ++ ) ;
5559 if ( delay == null )
5660 throw ;
57-
61+
5862 await Task . Delay ( delay . Value , cancellationToken ) . ConfigureAwait ( false ) ;
5963 }
6064 }
0 commit comments