mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-06 00:09:22 +00:00
Co-authored-by: ktx-vaidehi <vaidehi.akhani@kiara.tech> Co-authored-by: Kirtan Thakkar <kirtan@kiara.tech>
26 lines
446 B
TypeScript
26 lines
446 B
TypeScript
import { ref, type Ref } from "vue";
|
|
|
|
export const useLoading = (asyncFunction: any) => {
|
|
const isLoading = ref(false);
|
|
const error: Ref<any> = ref(null);
|
|
|
|
const execute = async () => {
|
|
isLoading.value = true;
|
|
error.value = null;
|
|
|
|
try {
|
|
await asyncFunction();
|
|
} catch (err) {
|
|
error.value = err;
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
};
|
|
|
|
return {
|
|
isLoading,
|
|
error,
|
|
execute,
|
|
};
|
|
};
|