From 305e421292c5bcdd5cbfd3a49cbfd4efcfac8bfd Mon Sep 17 00:00:00 2001 From: Omar Elsayed <125718818+EngOmarElsayed@users.noreply.github.com> Date: Mon, 1 Jun 2026 09:18:36 +0300 Subject: [PATCH] Add comments to prevent self deadlock explanation Added comments to explain the purpose of the task preventing self deadlock. --- Sources/TaskGate/AsyncGate.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/TaskGate/AsyncGate.swift b/Sources/TaskGate/AsyncGate.swift index f28f522..1bc2a57 100644 --- a/Sources/TaskGate/AsyncGate.swift +++ b/Sources/TaskGate/AsyncGate.swift @@ -125,6 +125,9 @@ public final class AsyncGate { return try await withTaskPriorityEscalationHandler { () throws(Failure) -> Result in try await body() } onPriorityEscalated: { _, newPriority in + // This task was added to prevent self deadlock from happening + // without it, deadlock could happen because `escalatePriority` + // will try to have the lock which is already in use by the same thread Task { uncheckedSelf.escalatePriority(to: newPriority) }