Add timeout to javascript queries

This commit is contained in:
Gabriel Augendre 2023-01-01 18:32:23 +01:00
parent 3e936313d5
commit 372cf830ae

View file

@ -1,13 +1,11 @@
function play() { function play() {
console.log("Play..."); console.log("Play...");
var xhttp = new XMLHttpRequest(); fetch("/play", { signal: AbortSignal.timeout(7000) });
xhttp.open("GET", "play", true);
xhttp.send();
} }
function loadAvailableFiles() { function loadAvailableFiles() {
console.log("Available files..."); console.log("Available files...");
fetch("/available-files") fetch("/available-files", { signal: AbortSignal.timeout(7000) })
.then(response => response.json()) .then(response => response.json())
.then(handleAvailableFiles); .then(handleAvailableFiles);
} }
@ -16,7 +14,7 @@ function selectFile(name) {
console.log("Select file"); console.log("Select file");
const body = new FormData(); const body = new FormData();
body.set("fileName", name); body.set("fileName", name);
fetch("/select-file", {method: "POST", body: body}) fetch("/select-file", { method: "POST", body: body, signal: AbortSignal.timeout(7000) })
.then(response => response.json()) .then(response => response.json())
.then(handleAvailableFiles); .then(handleAvailableFiles);
} }