feat: add new util function create-async-process

This commit is contained in:
Sándor Levcsák 2020-10-23 05:46:29 +03:00
parent cb1fbd81d0
commit e5d1f41dba
1 changed files with 14 additions and 0 deletions

View File

@ -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 }
}