Convert then chain into await statements

This commit is contained in:
Caleb Owens 2024-04-12 20:41:11 +01:00
parent 91ca426378
commit b3c2fd0c7e

View File

@ -68,22 +68,16 @@ export async function invoke<T>(command: string, params: Record<string, unknown>
// });
const loadingItem = { name: command, startedAt: new Date() };
isLoading.push(loadingItem);
return await invokeTauri<T>(command, params)
// .then((value) => {
// console.debug(`ipc->${command}(${JSON.stringify(params)})`, value);
// return value;
// })
.then((value) => {
return value;
})
.catch((reason) => {
const userError = UserError.fromError(reason);
console.error(`ipc->${command}: ${JSON.stringify(params)}`, userError, reason);
throw userError;
})
.finally(() => {
isLoading.pop(loadingItem);
});
try {
return await invokeTauri<T>(command, params);
} catch (reason) {
const userError = UserError.fromError(reason);
console.error(`ipc->${command}: ${JSON.stringify(params)}`, userError, reason);
throw userError;
} finally {
isLoading.pop(loadingItem);
}
}
export function listen<T>(event: EventName, handle: EventCallback<T>) {