Skip to content

Commit f9f3e3a

Browse files
authored
Use AnyHashableSendable from Concurrency Extras (#3428)
* Use `AnyHashableSendable` from Concurrency Extras Rather than use an ad hoc implementation with an `AnyHashable` under the hood that may not be concurrency safe, let's adopt the helper we added to the Concurrency Extras packages. * fix * wip * wip
1 parent 61e3809 commit f9f3e3a

File tree

9 files changed

+16
-32
lines changed

9 files changed

+16
-32
lines changed

.github/package.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/CaseStudies/SwiftUICaseStudies/03-Effects-LongLiving.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,17 @@ struct LongLivingEffects {
4848
}
4949

5050
extension DependencyValues {
51-
var screenshots: @Sendable () async -> AsyncStream<Void> {
51+
var screenshots: @Sendable () async -> any AsyncSequence<Void, Never> {
5252
get { self[ScreenshotsKey.self] }
5353
set { self[ScreenshotsKey.self] = newValue }
5454
}
5555
}
5656

5757
private enum ScreenshotsKey: DependencyKey {
58-
static let liveValue: @Sendable () async -> AsyncStream<Void> = {
59-
AsyncStream(
60-
NotificationCenter.default
61-
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
62-
.map { _ in }
63-
)
58+
static let liveValue: @Sendable () async -> any AsyncSequence<Void, Never> = {
59+
NotificationCenter.default
60+
.notifications(named: UIApplication.userDidTakeScreenshotNotification)
61+
.map { _ in }
6462
}
6563
}
6664

Examples/CaseStudies/SwiftUICaseStudies/FactClient.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,3 @@ extension FactClient: DependencyKey {
3030
/// to prove do not need the dependency.
3131
static let testValue = Self()
3232
}
33-
34-
struct AnyHashableSendable: Hashable, @unchecked Sendable {
35-
let base: AnyHashable
36-
init<Base: Hashable & Sendable>(_ base: Base) {
37-
self.base = base
38-
}
39-
}

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-collections", from: "1.1.0"),
2222
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.2"),
2323
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
24-
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
24+
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.2.0"),
2525
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-collections", from: "1.1.0"),
2222
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.2"),
2323
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
24-
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
24+
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.2.0"),
2525
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),

Sources/ComposableArchitecture/Effect.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ extension Effect {
4646

4747
/// Wraps an asynchronous unit of work that can emit actions any number of times in an effect.
4848
///
49-
/// For example, if you had an async stream in a dependency client:
49+
/// For example, if you had an async sequence in a dependency client:
5050
///
5151
/// ```swift
5252
/// struct EventsClient {
53-
/// var events: () -> AsyncStream<Event>
53+
/// var events: () -> any AsyncSequence<Event, Never>
5454
/// }
5555
/// ```
5656
///

Sources/ComposableArchitecture/Internal/NavigationID.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,3 @@ struct NavigationID: Hashable, @unchecked Sendable {
123123
hasher.combine(self.tag)
124124
}
125125
}
126-
127-
@_spi(Internals) public struct AnyHashableSendable: Hashable, @unchecked Sendable {
128-
@_spi(Internals) public let base: AnyHashable
129-
init<Base: Hashable & Sendable>(_ base: Base) {
130-
self.base = base
131-
}
132-
}

Tests/ComposableArchitectureTests/FileStorageTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ final class FileStorageTests: XCTestCase {
409409
await Task.yield()
410410
expectNoDifference(users, [.blob])
411411

412-
$users.withLock { $0 = [.blobJr] } // NB: Saved immediately
413-
$users.withLock { $0 = [.blobSr] } // NB: Throttled for 1 second
412+
await $users.withLock { $0 = [.blobJr] } // NB: Saved immediately
413+
await $users.withLock { $0 = [.blobSr] } // NB: Throttled for 1 second
414414
try FileManager.default.removeItem(at: .fileURL)
415415
try await Task.sleep(nanoseconds: 1_200_000_000)
416416
expectNoDifference(users, [.blob])

0 commit comments

Comments
 (0)