Skip to content

Commit

Permalink
WIP17
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgriff committed Oct 22, 2024
1 parent ee4a5ed commit cea60e9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion GenderPayGap.WebUI/Views/Search/SearchPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@
window.addEventListener("DOMContentLoaded", () => {
const NUMBER_OF_SEARCH_RESULTS_PER_TABLE = 100;
const aborter = (() => {
const abortControllers = [];
return {
abortPreviousFetchesAndGetNewAbortSignal: () => {
while(abortControllers.length > 0) {
const abortController = abortControllers.pop();
abortController.abort();
}
const abortController = new AbortController();
abortControllers.push(abortController);
return abortController.signal;
}
};
})();
const searchResultsIdGenerator = (() => {
let currentSearchResultsId = 0;
return {
Expand Down Expand Up @@ -407,7 +424,7 @@
const MIN_LOADING_DELAY_MILLISECONDS = 400;
const fetchStartTime = Date.now();
const response = await fetch(`${searchApiPath}${urlQuery}`);
const response = await fetch(`${searchApiPath}${urlQuery}`, { signal: aborter.abortPreviousFetchesAndGetNewAbortSignal() });
if (response.ok) {
const json = await response.json();
if (searchResultsIdGenerator.isCurrentId(searchResultsId)) {
Expand Down

0 comments on commit cea60e9

Please sign in to comment.