Add abort signal to task

This commit is contained in:
Stanislav Romanov 2023-03-02 10:57:10 +03:00
parent 6ad43d2851
commit 277b4d13a6
2 changed files with 22 additions and 25 deletions

View file

@ -19,9 +19,10 @@ export default class AdminTasksIndexController extends Controller {
@tracked indexUids;
@use
tasks = resource(() => {
tasks = resource(({ on }) => {
this.tasksHolder.isLoading = true;
const controller = new AbortController();
const params = {
limit: this.limit,
from: this.from,
@ -30,11 +31,17 @@ export default class AdminTasksIndexController extends Controller {
indexUids: this.indexUids,
};
this.meilisearch.getTasks(params).then((data) => {
this.tasksHolder.results = this.tasksHolder.results.concat(data.results);
this.tasksHolder.next = data.next;
this.tasksHolder.isLoading = false;
});
on.cleanup(() => controller.abort());
this.meilisearch
.getTasks(params, { signal: controller.signal })
.then((data) => {
this.tasksHolder.results = this.tasksHolder.results.concat(
data.results
);
this.tasksHolder.next = data.next;
this.tasksHolder.isLoading = false;
});
return this.tasksHolder;
});

View file

@ -16,29 +16,19 @@ export default function query(path, options = {}) {
Object.assign(options, { headers })
);
return fetch(req)
.then((response) => {
if (response.status === 204) {
return;
} else if (response.ok) {
return response.json();
} else {
return response.json().then((reason) => {
toaster.dangerToast({
header: reason.type,
text: reason.message,
});
// throw new Error('Network response was not OK');
});
}
})
.catch((response) => {
return fetch(req).then((response) => {
if (response.status === 204) {
return;
} else if (response.ok) {
return response.json();
} else {
return response.json().then((reason) => {
toaster.dangerToast({
header: reason.type,
text: reason.message,
});
// throw new Error('Network response was not OK');
});
});
}
});
}