@@ -19,6 +19,7 @@ public interface ITask : IAsyncResult
19
19
ITask Catch ( Func < Exception , bool > handler ) ;
20
20
ITask Finally ( Action handler ) ;
21
21
ITask Finally ( Action < bool , Exception > actionToContinueWith , TaskAffinity affinity = TaskAffinity . Concurrent ) ;
22
+ ITask Finally < T > ( T taskToContinueWith ) where T : ITask ;
22
23
ITask Start ( ) ;
23
24
ITask Start ( TaskScheduler scheduler ) ;
24
25
ITask Progress ( Action < IProgress > progressHandler ) ;
@@ -180,14 +181,11 @@ public ITask Finally(Action handler)
180
181
public ITask Finally ( Action < bool , Exception > actionToContinueWith , TaskAffinity affinity = TaskAffinity . Concurrent )
181
182
{
182
183
Guard . ArgumentNotNull ( actionToContinueWith , nameof ( actionToContinueWith ) ) ;
183
- var ret = Then ( new ActionTask ( Token , actionToContinueWith ) { Affinity = affinity , Name = "Finally" } , TaskRunOptions . Always ) ;
184
- DependsOn ? . SetFaultHandler ( ret ) ;
185
- ret . ContinuationIsFinally = true ;
186
- return ret ;
184
+ return Finally ( new ActionTask ( Token , actionToContinueWith ) { Affinity = affinity , Name = "Finally" } ) ;
187
185
}
188
186
189
- internal virtual ITask Finally < T > ( T taskToContinueWith )
190
- where T : TaskBase
187
+ public ITask Finally < T > ( T taskToContinueWith )
188
+ where T : ITask
191
189
{
192
190
Guard . ArgumentNotNull ( taskToContinueWith , nameof ( taskToContinueWith ) ) ;
193
191
continuationAlways = ( TaskBase ) ( object ) taskToContinueWith ;
@@ -340,7 +338,7 @@ protected virtual void RaiseOnStart()
340
338
protected virtual void RaiseOnEnd ( )
341
339
{
342
340
OnEnd ? . Invoke ( this ) ;
343
- if ( continuationOnSuccess == null && continuationOnFailure == null )
341
+ if ( continuationOnSuccess == null && continuationOnFailure == null && continuationAlways == null )
344
342
finallyHandler ? . Invoke ( ) ;
345
343
//Logger.Trace($"Finished {ToString()}");
346
344
}
@@ -396,7 +394,6 @@ public override string ToString()
396
394
protected ILogging Logger { get { return logger = logger ?? LogHelper . GetLogger ( GetType ( ) ) ; } }
397
395
public TaskBase DependsOn { get ; private set ; }
398
396
public CancellationToken Token { get ; }
399
- internal bool ContinuationIsFinally { get ; set ; }
400
397
}
401
398
402
399
abstract class TaskBase < TResult > : TaskBase , ITask < TResult >
@@ -495,7 +492,6 @@ public ITask<TResult> Finally(Func<bool, Exception, TResult, TResult> continuati
495
492
{
496
493
Guard . ArgumentNotNull ( continuation , "continuation" ) ;
497
494
var ret = Then ( new FuncTask < TResult , TResult > ( Token , continuation ) { Affinity = affinity , Name = "Finally" } , TaskRunOptions . Always ) ;
498
- ret . ContinuationIsFinally = true ;
499
495
DependsOn ? . SetFaultHandler ( ret ) ;
500
496
return ret ;
501
497
}
@@ -504,7 +500,6 @@ public ITask Finally(Action<bool, Exception, TResult> continuation, TaskAffinity
504
500
{
505
501
Guard . ArgumentNotNull ( continuation , "continuation" ) ;
506
502
var ret = Then ( new ActionTask < TResult > ( Token , continuation ) { Affinity = affinity , Name = "Finally" } , TaskRunOptions . Always ) ;
507
- ret . ContinuationIsFinally = true ;
508
503
DependsOn ? . SetFaultHandler ( ret ) ;
509
504
return ret ;
510
505
}
@@ -547,7 +542,7 @@ protected override void RaiseOnStart()
547
542
protected virtual void RaiseOnEnd ( TResult result )
548
543
{
549
544
OnEnd ? . Invoke ( this , result ) ;
550
- if ( continuationOnSuccess == null && continuationOnFailure == null )
545
+ if ( continuationOnSuccess == null && continuationOnFailure == null && continuationAlways == null )
551
546
finallyHandler ? . Invoke ( result ) ;
552
547
//Logger.Trace($"Finished {ToString()} {result}");
553
548
}
0 commit comments