From 081ca79161884a8d8aacd2dfea9dd89cd10ec2bf Mon Sep 17 00:00:00 2001 From: Doug Russell Date: Tue, 11 Oct 2022 14:54:17 -0400 Subject: [PATCH] Deprecation Housekeeping (#206) (#207) `withTaskCancellationHandler(_:, operation:)` -> `withTaskCancellationHandler(operation:onCancel:)` --- Sources/AsyncAlgorithms/Zip/Zip2Runtime.swift | 12 ++++++------ Sources/AsyncAlgorithms/Zip/Zip3Runtime.swift | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/AsyncAlgorithms/Zip/Zip2Runtime.swift b/Sources/AsyncAlgorithms/Zip/Zip2Runtime.swift index 02cc26b..86e875f 100644 --- a/Sources/AsyncAlgorithms/Zip/Zip2Runtime.swift +++ b/Sources/AsyncAlgorithms/Zip/Zip2Runtime.swift @@ -24,12 +24,6 @@ where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: func next() async rethrows -> (Base1.Element, Base2.Element)? { try await withTaskCancellationHandler { - let output = self.stateMachine.withCriticalRegion { stateMachine in - stateMachine.rootTaskIsCancelled() - } - // clean the allocated resources and state - self.handle(rootTaskIsCancelledOutput: output) - } operation: { let results = await withUnsafeContinuation { continuation in self.stateMachine.withCriticalRegion { stateMachine in let output = stateMachine.newDemandFromConsumer(suspendedDemand: continuation) @@ -59,6 +53,12 @@ where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: } return try (results.0._rethrowGet(), results.1._rethrowGet()) + } onCancel: { + let output = self.stateMachine.withCriticalRegion { stateMachine in + stateMachine.rootTaskIsCancelled() + } + // clean the allocated resources and state + self.handle(rootTaskIsCancelledOutput: output) } } diff --git a/Sources/AsyncAlgorithms/Zip/Zip3Runtime.swift b/Sources/AsyncAlgorithms/Zip/Zip3Runtime.swift index ee39310..63e83fd 100644 --- a/Sources/AsyncAlgorithms/Zip/Zip3Runtime.swift +++ b/Sources/AsyncAlgorithms/Zip/Zip3Runtime.swift @@ -26,12 +26,6 @@ where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: func next() async rethrows -> (Base1.Element, Base2.Element, Base3.Element)? { try await withTaskCancellationHandler { - let output = self.stateMachine.withCriticalRegion { stateMachine in - stateMachine.rootTaskIsCancelled() - } - // clean the allocated resources and state - self.handle(rootTaskIsCancelledOutput: output) - } operation: { let results = await withUnsafeContinuation { continuation in self.stateMachine.withCriticalRegion { stateMachine in let output = stateMachine.newDemandFromConsumer(suspendedDemand: continuation) @@ -61,6 +55,12 @@ where Base1: Sendable, Base1.Element: Sendable, Base2: Sendable, Base2.Element: } return try (results.0._rethrowGet(), results.1._rethrowGet(), results.2._rethrowGet()) + } onCancel: { + let output = self.stateMachine.withCriticalRegion { stateMachine in + stateMachine.rootTaskIsCancelled() + } + // clean the allocated resources and state + self.handle(rootTaskIsCancelledOutput: output) } }