From 0f9be9091cea27a1830ee5a73e8cd2bacd1e6b4a Mon Sep 17 00:00:00 2001 From: Brian Michel Date: Tue, 9 Jan 2024 09:01:10 -0500 Subject: [PATCH] Fix actuallyCancel logic --- Sources/_Helpers/URLSession+AsyncAwait.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/_Helpers/URLSession+AsyncAwait.swift b/Sources/_Helpers/URLSession+AsyncAwait.swift index 9b5d5261..6e5b14d5 100644 --- a/Sources/_Helpers/URLSession+AsyncAwait.swift +++ b/Sources/_Helpers/URLSession+AsyncAwait.swift @@ -54,8 +54,7 @@ private actor URLSessionTaskCancellationHelper { } private func actuallyCancel() { - state = .cancelled - + // Handle whatever needs to be done based on the current state switch state { case let .registered(task): task.cancel() @@ -64,6 +63,9 @@ private actor URLSessionTaskCancellationHelper { case .initialized: break } + + // Set state into cancelled to short circuit subsequent cancellations or registrations. + state = .cancelled } }