MCPcopy Create free account
hub / github.com/TanStack/query / canRun

Method canRun

packages/query-core/src/mutationCache.ts:227–242  ·  view source on GitHub ↗

* Checks whether a mutation can run now, given the other mutations in its `scope`. * @internal * @param mutation - The mutation to check. * @returns `true` if the mutation has no `scope`, or no other mutation in its scope is pending * ahead of it.

(mutation: Mutation<any, any, any, any>)

Source from the content-addressed store, hash-verified

225 * ahead of it.
226 */
227 canRun(mutation: Mutation<any, any, any, any>): boolean {
228 const scope = scopeFor(mutation)
229 if (typeof scope === 'string') {
230 const mutationsWithSameScope = this.#scopes.get(scope)
231 const firstPendingMutation = mutationsWithSameScope?.find(
232 (m) => m.state.status === 'pending',
233 )
234 // we can run if there is no current pending mutation (start use-case)
235 // or if WE are the first pending mutation (continue use-case)
236 return !firstPendingMutation || firstPendingMutation === mutation
237 } else {
238 // For unscoped mutations there are never any pending mutations in front of the
239 // current mutation
240 return true
241 }
242 }
243
244 /**
245 * Continues the next paused mutation in the same `scope` after a mutation finishes.

Callers 3

executeMethod · 0.80
canContinueFunction · 0.80
canStartFunction · 0.80

Calls 3

scopeForFunction · 0.85
getMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected