Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | // src/libs/loading
import type { Pinia } from 'pinia'
import {useLoadingStore} from '@/stores/loading'
export async function withLoading<T>(
fn: () => Promise<T> | T,
tag = 'withLoading',
pinia?: Pinia
): Promise<T> {
const s = pinia ? useLoadingStore(pinia) : useLoadingStore()
// const s = useLoadingStore()
// console.log(`lib start loading: ${tag}`)
const token = s.start(tag)
try {
return await fn()
} finally {
// console.log(`lib stop loading: ${JSON.stringify(token)}`)
s.stop(token)
}
}
|