Implement app start/stop and add app state polling for the moment
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
|
||||
import { fetcher } from 'pankow';
|
||||
import { sleep } from 'pankow/utils';
|
||||
|
||||
function create() {
|
||||
const accessToken = localStorage.token;
|
||||
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
|
||||
|
||||
return {
|
||||
async wait(id) {
|
||||
while(true) {
|
||||
let result;
|
||||
try {
|
||||
result = await fetcher.get(`${origin}/api/v1/tasks/${id}`, { access_token: accessToken });
|
||||
} catch (e) {
|
||||
return [e];
|
||||
}
|
||||
|
||||
if (!result.body.active) return [result.body.error, result.body.result];
|
||||
|
||||
await sleep(2000);
|
||||
}
|
||||
},
|
||||
async getLatestByType(type) {
|
||||
let error, result;
|
||||
try {
|
||||
@@ -49,7 +64,7 @@ function create() {
|
||||
|
||||
if (error || result.status !== 204) return [error || result];
|
||||
return [null];
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user