mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 20:44:34 +00:00
chore: lint
This commit is contained in:
parent
85bc401e47
commit
5e6c6fccc4
1 changed files with 17 additions and 15 deletions
|
@ -25,20 +25,20 @@ const props = defineProps<{
|
||||||
|
|
||||||
const note = ref<Misskey.entities.Note | null>(null);
|
const note = ref<Misskey.entities.Note | null>(null);
|
||||||
|
|
||||||
let timeoutId = null;
|
// eslint-disable-next-line id-denylist
|
||||||
|
let timeoutId: ReturnType<typeof window.setTimeout> | null = null;
|
||||||
|
|
||||||
async function sleep(ms: number): Promise<void> {
|
async function sleep(ms: number): Promise<void> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
resolve()
|
resolve();
|
||||||
}, ms);
|
}, ms);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Promise<T> {
|
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T> {
|
||||||
let lastResult: T = undefined!;
|
let lastResult: T;
|
||||||
const r = Math.random();
|
for (let i = 0; i < retryCount; i++) {
|
||||||
for(let i=0; i<retryCount; i++) {
|
|
||||||
const [ok, resultOrError] = await f()
|
const [ok, resultOrError] = await f()
|
||||||
.then(result => [true, result])
|
.then(result => [true, result])
|
||||||
.catch(err => [false, err]);
|
.catch(err => [false, err]);
|
||||||
|
@ -50,7 +50,7 @@ async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Pr
|
||||||
}
|
}
|
||||||
|
|
||||||
// RATE_LIMIT_EXCEEDED
|
// RATE_LIMIT_EXCEEDED
|
||||||
if (resultOrError?.id === "d5826d14-3982-4d2e-8011-b9e9f02499ef") {
|
if (resultOrError?.id === 'd5826d14-3982-4d2e-8011-b9e9f02499ef') {
|
||||||
await sleep(resultOrError?.info?.fullResetMs ?? 1000);
|
await sleep(resultOrError?.info?.fullResetMs ?? 1000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Pr
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.block.note == null) return;
|
if (props.block.note == null) return;
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = window.setTimeout(() => {
|
||||||
retryOnThrottle(() => misskeyApi('notes/show', { noteId: props.block.note })).then(result => {
|
retryOnThrottle(() => misskeyApi('notes/show', { noteId: props.block.note })).then(result => {
|
||||||
note.value = result;
|
note.value = result;
|
||||||
});
|
});
|
||||||
|
@ -70,7 +70,9 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
if (timeoutId !== null) clearTimeout(timeoutId);
|
if (timeoutId !== null) {
|
||||||
|
window.clearTimeout(timeoutId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue