Skip to content

Commit 63e5c43

Browse files
authored
Clean up suspend(while:) (#726)
1 parent b596de5 commit 63e5c43

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

Sources/ComposableArchitecture/Beta/Concurrency.swift

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -218,35 +218,10 @@ import SwiftUI
218218
/// - Parameter predicate: A predicate on `State` that determines for how long this method
219219
/// should suspend.
220220
public func suspend(while predicate: @escaping (State) -> Bool) async {
221-
let cancellable = Box<AnyCancellable?>(wrappedValue: nil)
222-
try? await withTaskCancellationHandler(
223-
handler: { cancellable.wrappedValue?.cancel() },
224-
operation: {
225-
try Task.checkCancellation()
226-
try await withUnsafeThrowingContinuation {
227-
(continuation: UnsafeContinuation<Void, Error>) in
228-
guard !Task.isCancelled else {
229-
continuation.resume(throwing: CancellationError())
230-
return
231-
}
232-
cancellable.wrappedValue = self.publisher
233-
.filter { !predicate($0) }
234-
.prefix(1)
235-
.sink { _ in
236-
continuation.resume()
237-
_ = cancellable
238-
}
239-
}
240-
}
241-
)
242-
}
243-
}
244-
245-
private class Box<Value> {
246-
var wrappedValue: Value
247-
248-
init(wrappedValue: Value) {
249-
self.wrappedValue = wrappedValue
221+
_ = await self.publisher
222+
.values
223+
.filter { !predicate($0) }
224+
.first(where: { _ in true })
250225
}
251226
}
252227
#endif

0 commit comments

Comments
 (0)