chore(front): 更新依赖项并添加异步重试和超时功能

This commit is contained in:
keven
2025-09-14 10:38:59 +08:00
parent b2c0e85844
commit 03ccd13f8f
3 changed files with 36 additions and 1 deletions

21
front/lib/asyncRetry.ts Normal file
View File

@@ -0,0 +1,21 @@
import asyncWait from './asyncWait'
interface AsyncRetryOptions {
retryCount?: number
delay?: number
}
const asyncRetry = async <T>(fn: () => Promise<T>, options: AsyncRetryOptions = {}) => {
const { retryCount = 3, delay = 1000 } = options || {}
await asyncWait(delay)
try {
return await fn()
} catch (error) {
if (retryCount > 0) {
return await asyncRetry(fn, { retryCount: retryCount - 1, delay: delay * 2 })
}
throw error
}
}
export default asyncRetry

13
front/lib/asyncTimeout.ts Normal file
View File

@@ -0,0 +1,13 @@
import asyncWait from './asyncWait'
const asyncTimeout = <T>(fn: () => Promise<T>, ms: number) => {
return Promise.race([
fn(),
async () => {
await asyncWait(ms)
throw new Error('timeout')
},
])
}
export default asyncTimeout

View File

@@ -37,9 +37,10 @@
"filesize": "^10.1.6",
"js-md5": "^0.8.3",
"lodash-es": "^4.17.21",
"lucide-vue-next": "^0.487.0",
"lucide-vue-next": "^0.542.0",
"markdown-it": "^14.1.0",
"motion-v": "^1.5.0",
"nanoid": "^5.1.5",
"nuxt": "3.18.0",
"nuxt-lucide-icons": "1.0.5",
"pinia": "^3.0.3",