Files
Stephen Celis cad094a6b2 Sendable miscellany: effects, publishers, etc. (#3317)
* `@preconcurrency @MainActor` isolation of `Store`

* Remove unneeded `@MainActor`s

* Remove thread checking code

* Remove unneeded `@MainActor`s

* Swift 5.10 compatibility fixes

* wip

* More 5.10 fixes

* wip

* fixes

* wip

* wip

* up the timeout

* wip

* Fixes

* wip

* wip

* wip

* wip

* wip

* Fix binding action sendability

* Address more binding action sendability

* more bindable action sendability

* more bindable action warnings

* fix

* Make `Effect.map` sendable

* Make `Effect.actions` sendable

Also moves it to the test target, since it's only really used there.

* Make `AnyPublisher.create` sendable

* Make `_SynthesizedConformance` sendable

* Avoid non-sendable captures of `self` in reducers

We can capture the sendable case path instead.

* Make `ViewStore.yield` sendable

* Address internal sendability warning

* fix

* Another small warning

---------

Co-authored-by: Brandon Williams <mbrandonw@hey.com>
2024-08-29 13:47:32 -07:00

29 lines
862 B
Swift

@preconcurrency import Combine
extension Effect where Action: Sendable {
@_spi(Internals) public var actions: AsyncStream<Action> {
switch self.operation {
case .none:
return .finished
case let .publisher(publisher):
return AsyncStream { continuation in
let cancellable = publisher.sink(
receiveCompletion: { _ in continuation.finish() },
receiveValue: { continuation.yield($0) }
)
continuation.onTermination = { _ in
cancellable.cancel()
}
}
case let .run(priority, operation):
return AsyncStream { continuation in
let task = Task(priority: priority) {
await operation(Send { action in continuation.yield(action) })
continuation.finish()
}
continuation.onTermination = { _ in task.cancel() }
}
}
}
}