mirror of
https://github.com/C9Glax/tranga-website.git
synced 2025-04-19 14:53:20 +02:00
Only make 1 request to an endpoint concurrently
This commit is contained in:
parent
a3046680ac
commit
211db3d4d5
@ -74,7 +74,12 @@ export function putData(uri: string, content: object | string | number | boolean
|
|||||||
return makeRequest("PUT", uri, content) as Promise<object>;
|
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> {
|
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,
|
return fetch(uri,
|
||||||
{
|
{
|
||||||
method: method,
|
method: method,
|
||||||
@ -113,7 +118,7 @@ function makeRequest(method: string, uri: string, content: object | string | num
|
|||||||
.catch(function(err : Error){
|
.catch(function(err : Error){
|
||||||
console.error(`Error ${method}ing Data ${uri}\n${err}`);
|
console.error(`Error ${method}ing Data ${uri}\n${err}`);
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
});
|
}).finally(() => currentlyRequestedEndpoints.splice(currentlyRequestedEndpoints.indexOf(id), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isValidUri(uri: string) : boolean{
|
export function isValidUri(uri: string) : boolean{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, {EventHandler, ReactElement, useEffect, useState} from 'react';
|
import React, {ReactElement, useEffect, useState} from 'react';
|
||||||
import JobFunctions from './JobFunctions';
|
import JobFunctions from './JobFunctions';
|
||||||
import '../styles/monitorMangaList.css';
|
import '../styles/monitorMangaList.css';
|
||||||
import {JobType} from "./interfaces/Jobs/IJob";
|
import {JobType} from "./interfaces/Jobs/IJob";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user