@daysnap/utils
Version:
23 lines (21 loc) • 510 B
JavaScript
// src/createWithLoading.ts
function createWithLoading(showLoading, defaultOptions) {
return function withLoading(fn, options = defaultOptions) {
return async (...params) => {
if (params.length > fn.length) {
options = params.pop();
}
const toast = options ? showLoading(options) : null;
try {
return await fn(...params);
} catch (error) {
throw error;
} finally {
toast?.close();
}
};
};
}
export {
createWithLoading
};