Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 39d7f45

Browse files
committed
We need to propagate finally handlers for ITask<T> types as well
1 parent a681d18 commit 39d7f45

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/GitHub.Api/Tasks/TaskBase.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,20 @@ protected TaskBase(Task<TResult> task)
550550

551551
public override T Then<T>(T continuation, TaskRunOptions runOptions = TaskRunOptions.OnSuccess, bool taskIsTopOfChain = false)
552552
{
553-
return base.Then<T>(continuation, runOptions, taskIsTopOfChain);
553+
var nextTask = base.Then<T>(continuation, runOptions, taskIsTopOfChain);
554+
var nextTaskBase = ((TaskBase)(object)nextTask);
555+
// if the current task has a fault handler that matches this signature, attach it to the chain we're appending
556+
if (finallyHandler != null)
557+
{
558+
TaskBase endOfChainTask = (TaskBase)nextTaskBase.GetEndOfChain();
559+
while (endOfChainTask != this && endOfChainTask != null)
560+
{
561+
if (endOfChainTask is TaskBase<TResult>)
562+
((TaskBase<TResult>)endOfChainTask).finallyHandler += finallyHandler;
563+
endOfChainTask = endOfChainTask.DependsOn;
564+
}
565+
}
566+
return nextTask;
554567
}
555568

556569
/// <summary>

0 commit comments

Comments
 (0)