@@ -17,37 +17,33 @@ internal static Task<T> WithCancellation<T>(this Task<T> task, CancellationToken
17
17
18
18
internal static async Task TimeoutAfter ( this Task task , TimeSpan timeout )
19
19
{
20
- using ( var timeoutCancellationTokenSource = new CancellationTokenSource ( ) )
21
- {
22
- var completedTask = await Task
23
- . WhenAny ( task , Task . Delay ( timeout , timeoutCancellationTokenSource . Token ) )
24
- . ConfigureAwait ( false ) ;
25
-
26
- if ( completedTask == task )
27
- {
28
- timeoutCancellationTokenSource . Cancel ( ) ;
29
- await task . ConfigureAwait ( false ) ;
30
- return ;
31
- }
20
+ using var timeoutCancellationTokenSource = new CancellationTokenSource ( ) ;
21
+ var completedTask = await Task
22
+ . WhenAny ( task , Task . Delay ( timeout , timeoutCancellationTokenSource . Token ) )
23
+ . ConfigureAwait ( false ) ;
32
24
33
- throw new TimeoutException ( "The operation has timed out." ) ;
25
+ if ( completedTask == task )
26
+ {
27
+ timeoutCancellationTokenSource . Cancel ( ) ;
28
+ await task . ConfigureAwait ( false ) ;
29
+ return ;
34
30
}
31
+
32
+ throw new TimeoutException ( "The operation has timed out." ) ;
35
33
}
36
34
37
35
internal static async Task < T > TimeoutAfter < T > ( this Task < T > task , TimeSpan timeout )
38
36
{
39
- using ( var timeoutCancellationTokenSource = new CancellationTokenSource ( ) )
37
+ using var timeoutCancellationTokenSource = new CancellationTokenSource ( ) ;
38
+ var completedTask = await Task
39
+ . WhenAny ( task , Task . Delay ( timeout , timeoutCancellationTokenSource . Token ) )
40
+ . ConfigureAwait ( false ) ;
41
+ if ( completedTask == task )
40
42
{
41
- var completedTask = await Task
42
- . WhenAny ( task , Task . Delay ( timeout , timeoutCancellationTokenSource . Token ) )
43
- . ConfigureAwait ( false ) ;
44
- if ( completedTask == task )
45
- {
46
- timeoutCancellationTokenSource . Cancel ( ) ;
47
- return await task . ConfigureAwait ( false ) ;
48
- }
49
-
50
- throw new TimeoutException ( "The operation has timed out." ) ;
43
+ timeoutCancellationTokenSource . Cancel ( ) ;
44
+ return await task . ConfigureAwait ( false ) ;
51
45
}
46
+
47
+ throw new TimeoutException ( "The operation has timed out." ) ;
52
48
}
53
49
}
0 commit comments