Only make 1 request to an endpoint concurrently

This commit is contained in:
glax 2025-03-20 00:58:12 +01:00
parent a3046680ac
commit 211db3d4d5
2 changed files with 7 additions and 2 deletions

View File

@ -74,7 +74,12 @@ export function putData(uri: string, content: object | string | number | boolean
return makeRequest("PUT", uri, content) as Promise<object>;
}
let currentlyRequestedEndpoints: string[] = [];
function makeRequest(method: string, uri: string, content: object | string | number | null | boolean) : Promise<object | void> {
const id = method + uri;
if(currentlyRequestedEndpoints.find(x => x == id) != undefined)
return Promise.reject(`Already requested: ${method} ${uri}`);
currentlyRequestedEndpoints.push(id);
return fetch(uri,
{
method: method,
@ -113,7 +118,7 @@ function makeRequest(method: string, uri: string, content: object | string | num
.catch(function(err : Error){
console.error(`Error ${method}ing Data ${uri}\n${err}`);
return Promise.reject();
});
}).finally(() => currentlyRequestedEndpoints.splice(currentlyRequestedEndpoints.indexOf(id), 1));
}
export function isValidUri(uri: string) : boolean{

View File

@ -1,4 +1,4 @@
import React, {EventHandler, ReactElement, useEffect, useState} from 'react';
import React, {ReactElement, useEffect, useState} from 'react';
import JobFunctions from './JobFunctions';
import '../styles/monitorMangaList.css';
import {JobType} from "./interfaces/Jobs/IJob";