File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,33 +45,6 @@ public async Task It_continues_to_run_after_an_error()
4545 Assert . True ( await callbackInvokedAfterError . Task ) ;
4646 }
4747
48- [ Fact ]
49- public async Task Stop_cancels_token_while_waiting ( )
50- {
51- var waitCanceled = false ;
52- var delayStarted = new TaskCompletionSource < bool > ( ) ;
53- var timer = new AsyncTimer (
54- callback : _ => throw new ( "Simulated!" ) ,
55- interval : TimeSpan . FromDays ( 7 ) ,
56- delayStrategy : async ( delayTime , token ) =>
57- {
58- delayStarted . SetResult ( true ) ;
59- try
60- {
61- await Task . Delay ( delayTime , token ) ;
62- }
63- catch ( OperationCanceledException )
64- {
65- waitCanceled = true ;
66- }
67- } ) ;
68-
69- await delayStarted . Task ;
70- await timer . DisposeAsync ( ) ;
71-
72- Assert . True ( waitCanceled ) ;
73- }
74-
7548 [ Fact ]
7649 public async Task Stop_cancels_token_while_in_callback ( )
7750 {
Original file line number Diff line number Diff line change 44 Func < CancellationToken , Task > callback ;
55 TimeSpan interval ;
66 Action < Exception > errorCallback ;
7- Func < TimeSpan , CancellationToken , Task > delayStrategy ;
87 Task task ;
98 CancellationTokenSource tokenSource = new ( ) ;
109
1110 public AsyncTimer (
1211 Func < CancellationToken , Task > callback ,
1312 TimeSpan interval ,
14- Action < Exception > ? errorCallback = null ,
15- Func < TimeSpan , CancellationToken , Task > ? delayStrategy = null )
13+ Action < Exception > ? errorCallback = null )
1614 {
1715 this . callback = callback ;
1816 this . interval = interval ;
1917 this . errorCallback = errorCallback ?? ( _ =>
2018 {
2119 } ) ;
22- this . delayStrategy = delayStrategy ?? Task . Delay ;
2320 var cancellation = tokenSource . Token ;
2421
2522 task = Task . Run (
@@ -36,7 +33,7 @@ async Task RunLoop(CancellationToken cancellation)
3633 {
3734 try
3835 {
39- await delayStrategy ( interval , cancellation ) ;
36+ await Task . Delay ( interval , cancellation ) ;
4037 await callback ( cancellation ) ;
4138 }
4239 catch ( OperationCanceledException )
You can’t perform that action at this time.
0 commit comments