mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-20 21:49:26 +08:00
31 lines
740 B
TypeScript
31 lines
740 B
TypeScript
|
import axios, { AxiosRequestConfig } from 'axios';
|
||
|
|
||
|
class LoadTask<T> {
|
||
|
loaded: boolean = false;
|
||
|
promise?: Promise<T>;
|
||
|
url: string;
|
||
|
config?: AxiosRequestConfig<T>;
|
||
|
|
||
|
constructor(url: string, config?: AxiosRequestConfig<T>) {
|
||
|
this.url = url;
|
||
|
this.config = config;
|
||
|
}
|
||
|
|
||
|
load() {
|
||
|
if (this.promise) return this.promise;
|
||
|
|
||
|
return (this.promise = axios.get(this.url, this.config));
|
||
|
}
|
||
|
|
||
|
static list: Promise<any>[] = [];
|
||
|
static push(...tasks: LoadTask<any>[]) {
|
||
|
this.list.push(...tasks.map(v => v.load()));
|
||
|
}
|
||
|
|
||
|
static onEnd<T extends any[] = any[]>(): Promise<T> {
|
||
|
return Promise.all(LoadTask.list) as Promise<T>;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default function load() {}
|