Skip to content

Commit 656545a

Browse files
Stijn Willemsclaude
andcommitted
refactor: Remove unused swift-perception dependency, target macOS 15+ only
- Remove `import Perception` from FetchSubscription.swift (was unused) - Add explicit `import ConcurrencyExtras` for LockIsolated - Remove swift-perception package dependency from Package.swift - Update platforms to macOS 15+ only (drop iOS/tvOS/watchOS) - Update Package@swift-6.0.swift similarly The Perception import was never actually used - the file only uses LockIsolated (from ConcurrencyExtras) and SharedReader (from Sharing). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6308a48 commit 656545a

3 files changed

Lines changed: 48 additions & 8 deletions

File tree

Package.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "sqlite-data",
77
platforms: [
8-
.iOS(.v13),
9-
.macOS(.v10_15),
10-
.tvOS(.v13),
11-
.watchOS(.v7),
8+
.macOS(.v15),
129
],
1310
products: [
1411
.library(

Package@swift-6.0.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import PackageDescription
55
let package = Package(
66
name: "sqlite-data",
77
platforms: [
8-
.iOS(.v13),
9-
.macOS(.v10_15),
10-
.tvOS(.v13),
11-
.watchOS(.v7),
8+
.macOS(.v15),
129
],
1310
products: [
1411
.library(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import ConcurrencyExtras
2+
import Sharing
3+
4+
/// A subscription associated with `@FetchAll`, `@FetchOne`, and `@Fetch` observation.
5+
///
6+
/// This value can be useful in associating the lifetime of observing a query to the lifetime of a
7+
/// SwiftUI view _via_ the `task` view modifier. For example, loading a query in a view's `task`
8+
/// will automatically cancel the observation when drilling down into a child view, and restart
9+
/// observation when popping back to the view:
10+
///
11+
/// ```swift
12+
/// .task {
13+
/// try? await $reminders.load(Reminder.all).task
14+
/// }
15+
/// ```
16+
public struct FetchSubscription: Sendable {
17+
let cancellable = LockIsolated<Task<Void, any Error>?>(nil)
18+
let onCancel: @Sendable () -> Void
19+
20+
init<Value>(sharedReader: SharedReader<Value>) {
21+
onCancel = { sharedReader.projectedValue = SharedReader(value: sharedReader.wrappedValue) }
22+
}
23+
24+
/// An async handle to the given fetch observation.
25+
///
26+
/// This handle will suspend until the current task is cancelled, at which point it will terminate
27+
/// the observation of the associated ``FetchAll``, ``FetchOne``, or ``Fetch``.
28+
public var task: Void {
29+
get async throws {
30+
let task = Task {
31+
try await withTaskCancellationHandler {
32+
try await Task.never()
33+
} onCancel: {
34+
onCancel()
35+
}
36+
}
37+
cancellable.withValue { $0 = task }
38+
try await task.cancellableValue
39+
}
40+
}
41+
42+
/// Cancels the database observation of the associated ``FetchAll``, ``FetchOne``, or ``Fetch``.
43+
public func cancel() {
44+
cancellable.value?.cancel()
45+
}
46+
}

0 commit comments

Comments
 (0)