feat: add new util function create-async-process
This commit is contained in:
parent
cb1fbd81d0
commit
e5d1f41dba
|
|
@ -0,0 +1,14 @@
|
|||
import { ref } from 'vue'
|
||||
|
||||
export default function createAsyncProcess<T extends (...args: any) => Promise<any>> (fn: T) {
|
||||
const active = ref<boolean>(false)
|
||||
|
||||
async function run (): Promise<ReturnType<T>> {
|
||||
active.value = true
|
||||
const result = await fn()
|
||||
active.value = false
|
||||
return result
|
||||
}
|
||||
|
||||
return { active, run }
|
||||
}
|
||||
Loading…
Reference in New Issue