Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Improve request abort logic
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed May 7, 2025
commit 4d336f16aa267d139da81fbfbe940afe8bb2357d
10 changes: 8 additions & 2 deletions src/mixins/AbortControllerMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export default defineComponent({
}
},

methods: {
abortPendingRequest() {
this.abortController.abort()
this.abortController = new AbortController()
},
},

beforeDestroy() {
this.abortController.abort()
},

beforeRouteLeave(from, to, next) {
this.abortController.abort()
this.abortController = new AbortController()
this.abortPendingRequest()
next()
},
})
4 changes: 3 additions & 1 deletion src/mixins/FetchFilesMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineComponent({
return []
}

const signal = this.abortController.signal
const fetchSemaphoreSymbol = await this.fetchSemaphore.acquire()

try {
Expand All @@ -65,7 +66,7 @@ export default defineComponent({
firstResult: this.fetchedFileIds.length,
nbResults: numberOfImagesPerBatch,
...options,
signal: this.abortController.signal,
signal,
})

// If we get less files than requested that means we got to the end
Expand Down Expand Up @@ -121,6 +122,7 @@ export default defineComponent({
},

resetFetchFilesState() {
this.abortPendingRequest()
this.doneFetchingFiles = false
this.errorFetchingFiles = null
this.loadingFiles = false
Expand Down