@@ -139,11 +139,14 @@ public struct Fetch<Value: Sendable>: Sendable {
139139 /// - request: A request describing the data to fetch.
140140 /// - database: The database to read from. A value of `nil` will use the default database
141141 /// (`@Dependency(\.defaultDatabase)`).
142+ /// - Returns: A subscription associated with the observation.
143+ @discardableResult
142144 public func load(
143145 _ request: some FetchKeyRequest < Value > ,
144146 database: ( any DatabaseReader ) ? = nil
145- ) async throws {
147+ ) async throws -> FetchSubscription {
146148 try await sharedReader. load ( . fetch( request, database: databaseOrDefault ( database) ) )
149+ return FetchSubscription ( sharedReader: sharedReader)
147150 }
148151}
149152
@@ -183,13 +186,15 @@ extension Fetch {
183186 /// (`@Dependency(\.defaultDatabase)`).
184187 /// - scheduler: The scheduler to observe from. By default, database observation is performed
185188 /// asynchronously on the main queue.
189+ /// - Returns: A subscription associated with the observation.
190+ @discardableResult
186191 public func load(
187192 _ request: some FetchKeyRequest < Value > ,
188193 database: ( any DatabaseReader ) ? = nil ,
189194 scheduler: some ValueObservationScheduler & Hashable
190- ) async throws {
191- try await sharedReader. load (
192- . fetch ( request , database : databaseOrDefault ( database ) , scheduler : scheduler ) )
195+ ) async throws -> FetchSubscription {
196+ try await sharedReader. load ( . fetch ( request , database : databaseOrDefault ( database ) , scheduler : scheduler ) )
197+ return FetchSubscription ( sharedReader : sharedReader )
193198 }
194199}
195200
@@ -271,14 +276,16 @@ extension Fetch: Equatable where Value: Equatable {
271276 /// (`@Dependency(\.defaultDatabase)`).
272277 /// - animation: The animation to use for user interface changes that result from changes to
273278 /// the fetched results.
279+ /// - Returns: A subscription associated with the observation.
274280 @available ( iOS 17 , macOS 14 , tvOS 17 , watchOS 10 , * )
281+ @discardableResult
275282 public func load(
276283 _ request: some FetchKeyRequest < Value > ,
277284 database: ( any DatabaseReader ) ? = nil ,
278285 animation: Animation
279- ) async throws {
280- try await sharedReader. load (
281- . fetch ( request , database : databaseOrDefault ( database ) , animation : animation ) )
286+ ) async throws -> FetchSubscription {
287+ try await sharedReader. load ( . fetch ( request , database : databaseOrDefault ( database ) , animation : animation ) )
288+ return FetchSubscription ( sharedReader : sharedReader )
282289 }
283290 }
284291#endif
0 commit comments