retry fetching group info

This commit is contained in:
lilydjwg 2021-10-12 19:05:50 +08:00
parent d7cab6461f
commit f1d931107c
2 changed files with 22 additions and 5 deletions

View File

@ -2,6 +2,7 @@
import { onMount, setContext } from 'svelte'
import Message from './Message.svelte'
import Name from './Name.svelte'
import { sleep } from './util.js'
const LUOXU_URL = 'https://lab.lilydjwg.me/luoxu'
let groups = []
@ -30,12 +31,20 @@
onMount(async () => {
do_hash_search()
while(true) {
try{
const res = await fetch(`${LUOXU_URL}/groups`)
groups = (await res.json()).groups
need_update_title = true
if(!group) {
group = ''
}
break
}catch(e){
console.error('failed to fetch group info, will retry', e)
await sleep(1000)
}
}
})
$: {

8
src/util.js Normal file
View File

@ -0,0 +1,8 @@
'use strict'
export function sleep(ms) {
const p = new Promise((resolve, reject) => {
setTimeout(resolve, ms)
})
return p
}