@@ -25,8 +25,15 @@ public protocol PagerType {
25
25
callbackQueue: DispatchQueue ,
26
26
completion: ( ( PaginationError ? ) -> Void ) ?
27
27
)
28
- func refetch( cachePolicy: CachePolicy )
29
- func fetch( )
28
+ func refetch(
29
+ cachePolicy: CachePolicy ,
30
+ callbackQueue: DispatchQueue ,
31
+ completion: ( ( ) -> Void ) ?
32
+ )
33
+ func fetch(
34
+ callbackQueue: DispatchQueue ,
35
+ completion: ( ( ) -> Void ) ?
36
+ )
30
37
}
31
38
32
39
/// Handles pagination in the queue by managing multiple query watchers.
@@ -151,9 +158,17 @@ class GraphQLQueryPagerCoordinator<InitialQuery: GraphQLQuery, PaginatedQuery: G
151
158
}
152
159
153
160
/// Discards pagination state and fetches the first page from scratch.
154
- /// - Parameter cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
155
- func refetch( cachePolicy: CachePolicy = . fetchIgnoringCacheData) {
156
- Task {
161
+ /// - Parameters:
162
+ /// - cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
163
+ /// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
164
+ /// - completion: A completion block that will always trigger after the execution of this operation.
165
+ func refetch(
166
+ cachePolicy: CachePolicy = . fetchIgnoringCacheData,
167
+ callbackQueue: DispatchQueue = . main,
168
+ completion: ( ( ) -> Void ) ? = nil
169
+ ) {
170
+ execute ( callbackQueue: callbackQueue, completion: { _ in completion ? ( ) } ) { [ weak self] in
171
+ guard let self else { return }
157
172
for completion in await self . completionManager. completions {
158
173
completion. execute ( error: PaginationError . cancellation)
159
174
}
@@ -162,9 +177,15 @@ class GraphQLQueryPagerCoordinator<InitialQuery: GraphQLQuery, PaginatedQuery: G
162
177
}
163
178
164
179
/// Fetches the first page.
165
- func fetch( ) {
166
- Task {
167
- await pager. fetch ( )
180
+ /// - Parameters:
181
+ /// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
182
+ /// - completion: A completion block that will always trigger after the execution of this operation.
183
+ func fetch(
184
+ callbackQueue: DispatchQueue = . main,
185
+ completion: ( ( ) -> Void ) ? = nil
186
+ ) {
187
+ execute ( callbackQueue: callbackQueue, completion: { _ in completion ? ( ) } ) { [ weak self] in
188
+ await self ? . pager. fetch ( )
168
189
}
169
190
}
170
191
0 commit comments