@@ -98,11 +98,14 @@ public struct Fetch<Value: Sendable>: Sendable {
9898 /// - request: A request describing the data to fetch.
9999 /// - database: The database to read from. A value of `nil` will use the default database
100100 /// (`@Dependency(\.defaultDatabase)`).
101+ /// - Returns: A subscription associated with the observation.
102+ @discardableResult
101103 public func load(
102104 _ request: some FetchKeyRequest < Value > ,
103105 database: ( any DatabaseReader ) ? = nil
104- ) async throws {
106+ ) async throws -> FetchSubscription {
105107 try await sharedReader. load ( . fetch( request, database: database) )
108+ return FetchSubscription ( sharedReader: sharedReader)
106109 }
107110}
108111
@@ -136,12 +139,15 @@ extension Fetch {
136139 /// (`@Dependency(\.defaultDatabase)`).
137140 /// - scheduler: The scheduler to observe from. By default, database observation is performed
138141 /// asynchronously on the main queue.
142+ /// - Returns: A subscription associated with the observation.
143+ @discardableResult
139144 public func load(
140145 _ request: some FetchKeyRequest < Value > ,
141146 database: ( any DatabaseReader ) ? = nil ,
142147 scheduler: some ValueObservationScheduler & Hashable
143- ) async throws {
148+ ) async throws -> FetchSubscription {
144149 try await sharedReader. load ( . fetch( request, database: database, scheduler: scheduler) )
150+ return FetchSubscription ( sharedReader: sharedReader)
145151 }
146152}
147153
@@ -193,13 +199,16 @@ extension Fetch: Equatable where Value: Equatable {
193199 /// (`@Dependency(\.defaultDatabase)`).
194200 /// - animation: The animation to use for user interface changes that result from changes to
195201 /// the fetched results.
202+ /// - Returns: A subscription associated with the observation.
196203 @available ( iOS 17 , macOS 14 , tvOS 17 , watchOS 10 , * )
204+ @discardableResult
197205 public func load(
198206 _ request: some FetchKeyRequest < Value > ,
199207 database: ( any DatabaseReader ) ? = nil ,
200208 animation: Animation
201- ) async throws {
209+ ) async throws -> FetchSubscription {
202210 try await sharedReader. load ( . fetch( request, database: database, animation: animation) )
211+ return FetchSubscription ( sharedReader: sharedReader)
203212 }
204213 }
205214#endif
0 commit comments