wuhu-torn-helper/src/func/utils/autoFetchJSON.ts
2022-09-19 18:31:24 +08:00

28 lines
663 B
TypeScript

import Utils from "../../class/Utils";
import WuhuBase from "../../class/WuhuBase";
/**
* 循环获取json对象
* @param dest
* @param time
*/
function autoFetchJSON(dest, time = 30) {
let obj;
const res = Utils.COFetch(dest);
setInterval(async () => {
if (!WuhuBase.glob.isWindowActive()) return;
const res = await Utils.COFetch(dest);
obj = JSON.parse(res);
}, time * 1000);
return {
get: async function () {
if (!obj) {
const str = await res
return obj = JSON.parse(str);
}
return obj;
}
};
}
export default autoFetchJSON