Skip to content

Commit b272014

Browse files
stephencelismluisbrown
authored andcommitted
Fix warnings introduced in Xcode 14.1 (#1388)
* Fix warnings introduced in Xcode 14.1 * wip (cherry picked from commit bcdcb3d7091d57a3e9cf5370b345a9309d205d39) # Conflicts: # Sources/ComposableArchitecture/Internal/TaskCancellableValue.swift # Sources/ComposableArchitecture/ViewStore.swift
1 parent bfd374e commit b272014

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

Examples/VoiceMemos/VoiceMemos/AudioRecorderClient/LiveAudioRecorderClient.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ private actor AudioRecorder {
7979
}
8080
}
8181

82-
guard let action = try await stream.first(where: { @Sendable _ in true })
83-
else { throw CancellationError() }
84-
return action
82+
for try await didFinish in stream {
83+
return didFinish
84+
}
85+
throw CancellationError()
8586
}
8687
}
8788

Sources/ComposableArchitecture/Internal/TaskCancellableValue.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
var cancellableValue: Success {
44
get async throws {
55
try await withTaskCancellationHandler {
6-
self.cancel()
7-
} operation: {
86
try await self.value
7+
} onCancel: {
8+
self.cancel()
99
}
1010
}
1111
}
@@ -16,9 +16,9 @@
1616
var cancellableValue: Success {
1717
get async {
1818
await withTaskCancellationHandler {
19-
self.cancel()
20-
} operation: {
2119
await self.value
20+
} onCancel: {
21+
self.cancel()
2222
}
2323
}
2424
}

Sources/ComposableArchitecture/Store.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,13 @@ public final class Store<State, Action> {
422422
var index = tasks.wrappedValue.startIndex
423423
while index < tasks.wrappedValue.endIndex {
424424
defer { index += 1 }
425-
tasks.wrappedValue[index].cancel()
425+
await tasks.wrappedValue[index].value
426426
}
427-
} operation: {
427+
} onCancel: {
428428
var index = tasks.wrappedValue.startIndex
429429
while index < tasks.wrappedValue.endIndex {
430430
defer { index += 1 }
431-
await tasks.wrappedValue[index].value
431+
tasks.wrappedValue[index].cancel()
432432
}
433433
}
434434
}

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ public final class ViewStore<State, Action> {
264264
public func send(_ action: Action, while predicate: @escaping (State) -> Bool) async {
265265
let task = self.send(action)
266266
await withTaskCancellationHandler {
267-
task.rawValue?.cancel()
268-
} operation: {
269267
await self.yield(while: predicate)
268+
} onCancel: {
269+
task.rawValue?.cancel()
270270
}
271271
}
272272

@@ -287,9 +287,9 @@ public final class ViewStore<State, Action> {
287287
) async {
288288
let task = withAnimation(animation) { self.send(action) }
289289
await withTaskCancellationHandler {
290-
task.rawValue?.cancel()
291-
} operation: {
292290
await self.yield(while: predicate)
291+
} onCancel: {
292+
task.rawValue?.cancel()
293293
}
294294
}
295295
#endif
@@ -304,31 +304,30 @@ public final class ViewStore<State, Action> {
304304
@MainActor
305305
public func yield(while predicate: @escaping (State) -> Bool) async {
306306
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
307-
_ = await self.produced.producer
307+
_ = await self.produced.producer
308308
.values
309309
.first(where: { !predicate($0) })
310310
} else {
311311
let cancellable = Box<Disposable?>(wrappedValue: nil)
312-
try? await withTaskCancellationHandler(
313-
handler: { cancellable.wrappedValue?.dispose() },
314-
operation: {
315-
try Task.checkCancellation()
316-
try await withUnsafeThrowingContinuation {
317-
(continuation: UnsafeContinuation<Void, Error>) in
318-
guard !Task.isCancelled else {
319-
continuation.resume(throwing: CancellationError())
320-
return
321-
}
322-
cancellable.wrappedValue = self.produced.producer
323-
.filter { !predicate($0) }
324-
.take(first: 1)
325-
.startWithValues { _ in
326-
continuation.resume()
327-
_ = cancellable
328-
}
312+
try? await withTaskCancellationHandler {
313+
try Task.checkCancellation()
314+
try await withUnsafeThrowingContinuation {
315+
(continuation: UnsafeContinuation<Void, Error>) in
316+
guard !Task.isCancelled else {
317+
continuation.resume(throwing: CancellationError())
318+
return
329319
}
320+
cancellable.wrappedValue = self.produced.producer
321+
.filter { !predicate($0) }
322+
.take(first: 1)
323+
.startWithValues { _ in
324+
continuation.resume()
325+
_ = cancellable
326+
}
330327
}
331-
)
328+
} onCancel: {
329+
cancellable.wrappedValue?.dispose()
330+
}
332331
}
333332
}
334333
#endif

0 commit comments

Comments
 (0)