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);
|
||||
|
||||
let timeoutId = null;
|
||||
// eslint-disable-next-line id-denylist
|
||||
let timeoutId: ReturnType<typeof window.setTimeout> | null = null;
|
||||
|
||||
async function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
window.setTimeout(() => {
|
||||
resolve();
|
||||
}, ms);
|
||||
});
|
||||
}
|
||||
|
||||
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Promise<T> {
|
||||
let lastResult: T = undefined!;
|
||||
const r = Math.random();
|
||||
for(let i=0; i<retryCount; i++) {
|
||||
async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount = 5): Promise<T> {
|
||||
let lastResult: T;
|
||||
for (let i = 0; i < retryCount; i++) {
|
||||
const [ok, resultOrError] = await f()
|
||||
.then(result => [true, result])
|
||||
.catch(err => [false, err]);
|
||||
|
@ -50,7 +50,7 @@ async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Pr
|
|||
}
|
||||
|
||||
// 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);
|
||||
continue;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ async function retryOnThrottle<T>(f: ()=>Promise<T>, retryCount: number = 5): Pr
|
|||
|
||||
onMounted(() => {
|
||||
if (props.block.note == null) return;
|
||||
timeoutId = setTimeout(() => {
|
||||
timeoutId = window.setTimeout(() => {
|
||||
retryOnThrottle(() => misskeyApi('notes/show', { noteId: props.block.note })).then(result => {
|
||||
note.value = result;
|
||||
});
|
||||
|
@ -70,7 +70,9 @@ onMounted(() => {
|
|||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timeoutId !== null) clearTimeout(timeoutId);
|
||||
if (timeoutId !== null) {
|
||||
window.clearTimeout(timeoutId);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue