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

Method canRun

packages/query-core/src/mutationCache.ts:216–231  ·  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

214 * ahead of it.
215 */
216 canRun(mutation: Mutation<any, any, any, any>): boolean {
217 const scope = scopeFor(mutation)
218 if (typeof scope === 'string') {
219 const mutationsWithSameScope = this.#scopes.get(scope)
220 const firstPendingMutation = mutationsWithSameScope?.find(
221 (m) => m.state.status === 'pending',
222 )
223 // we can run if there is no current pending mutation (start use-case)
224 // or if WE are the first pending mutation (continue use-case)
225 return !firstPendingMutation || firstPendingMutation === mutation
226 } else {
227 // For unscoped mutations there are never any pending mutations in front of the
228 // current mutation
229 return true
230 }
231 }
232
233 /**
234 * 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