Skip to content

Commit c98027c

Browse files
committed
Skip over transparent non-user continuations
1 parent b802826 commit c98027c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/coreclr/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncHelpers.CoreCLR.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,16 @@ public static void HandleSuspended<T, TOps>(T task) where T : Task, ITaskComplet
607607
// the continuation chain builds from the innermost frame out and at the time when the
608608
// notifier is created we do not know yet if the caller wants to continue on a context.
609609
ValueTaskSourceOnCompletedFlags configFlags = ValueTaskSourceOnCompletedFlags.None;
610-
ContinuationFlags continuationFlags = headContinuation.Next!.Flags;
611610

611+
// skip to the next non-transparent continuation, if such exists
612+
Continuation nextUserContinuaton = headContinuation;
613+
while ((nextUserContinuaton.Flags & continueFlags) == 0 &&
614+
nextUserContinuaton.Next != null)
615+
{
616+
nextUserContinuaton = nextUserContinuaton.Next;
617+
}
618+
619+
ContinuationFlags continuationFlags = nextUserContinuaton.Flags;
612620
const ContinuationFlags continueOnContextFlags =
613621
ContinuationFlags.ContinueOnCapturedSynchronizationContext |
614622
ContinuationFlags.ContinueOnCapturedTaskScheduler;
@@ -620,7 +628,7 @@ public static void HandleSuspended<T, TOps>(T task) where T : Task, ITaskComplet
620628
}
621629

622630
// Clear continuation flags, so that continuation runs transparently
623-
headContinuation.Next!.Flags &= ~continueFlags;
631+
nextUserContinuaton.Flags &= ~continueFlags;
624632
TOps.ValueTaskSourceOnCompleted(task, vtsNotifier, configFlags);
625633
}
626634
else

0 commit comments

Comments
 (0)