mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
chore(front): 更新依赖项并添加异步重试和超时功能
This commit is contained in:
21
front/lib/asyncRetry.ts
Normal file
21
front/lib/asyncRetry.ts
Normal 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
13
front/lib/asyncTimeout.ts
Normal 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
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user