Skip to content

Commit

Permalink
fix: cancelQueries now uses the query.cancel method
Browse files Browse the repository at this point in the history
fix: query.cancelQueries was renamed to query.cancelPromises
  • Loading branch information
tannerlinsley committed May 15, 2020
1 parent 3ef9c7c commit 80e82da
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/queryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ export function makeQueryCache() {
const foundQueries = findQueries(predicate, { exact })

foundQueries.forEach(query => {
query.cancelled = cancelledError

if (query.cancelQueries) {
query.cancelQueries()
}
query.cancel()
})

if (foundQueries.length) {
Expand Down Expand Up @@ -327,6 +323,18 @@ export function makeQueryCache() {
query.cancelled = null
}

query.cancel = () => {
query.cancelled = cancelledError

if (query.cancelPromises) {
query.cancelPromises()
}

delete query.promise

notifyGlobalListeners()
}

query.updateInstance = instance => {
let found = query.instances.find(d => d.id === instance.id)

Expand All @@ -349,12 +357,7 @@ export function makeQueryCache() {
query.instances = query.instances.filter(d => d.id !== instanceId)

if (!query.instances.length) {
// Cancel any side-effects
query.cancelled = cancelledError

if (query.cancelQueries) {
query.cancelQueries()
}
query.cancel()

// Schedule garbage collection
query.scheduleGarbageCollection()
Expand All @@ -368,16 +371,16 @@ export function makeQueryCache() {
// Perform the query
const promise = queryFn(...query.config.queryFnParamsFilter(args))

query.cancelQueries = () => promise.cancel?.()
query.cancelPromises = () => promise.cancel?.()

const data = await promise

delete query.cancelQueries
delete query.cancelPromises
if (query.cancelled) throw query.cancelled

return data
} catch (error) {
delete query.cancelQueries
delete query.cancelPromises
if (query.cancelled) throw query.cancelled

// If we fail, increase the failureCount
Expand Down

0 comments on commit 80e82da

Please sign in to comment.