@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
34 lines • 1.16 kB
JavaScript
import { observe, LazyPromise } from "./async/_module-exports.js";
import { AsyncHooks, TimeSpan } from "./utilities/_module-exports.js";
await new AsyncHooks(
// Lets pretend this function can throw and takes time to execute.
async (a, b) => {
const shouldThrow1 = Math.round(Math.random() * 100);
if (shouldThrow1 > 50) {
throw new Error("Unexpected error occured");
}
await LazyPromise.delay(TimeSpan.fromMilliseconds(Math.random() * 1000));
const shouldThrow2 = Math.round(Math.random() * 100);
if (shouldThrow2 > 50) {
throw new Error("Unexpected error occured");
}
return a / b;
}, observe({
onStart: (data) => {
console.log("START:", data);
},
onSuccess: (data) => {
console.log("SUCCESS:", data);
},
onError: (data) => {
console.error("ERROR:", data);
},
onFinally: (data) => {
console.log("FINALLY:", data);
},
})).invoke(20, 10);
// Will log when the function execution has started.
// Will log if the function succeded.
// Will log if the function errored and the error.
// Will log the execution time
//# sourceMappingURL=test.js.map