wuhu-torn-helper/function/utils/autoFetchJSON.ts

25 lines
552 B
TypeScript

/**
* 循环获取json对象
* @param dest
* @param time
*/
function autoFetchJSON(dest, time = 30) {
let obj;
const res = COFetch(dest);
setInterval(async () => {
if (!isWindowActive()) return;
const res = await 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