sussy-util
Version:
Util package made by me
20 lines (19 loc) • 605 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Asynchronous error handling function.
* @template T - The error type.
* @template R - The result type.
* @param {(...args: any[]) => PromiseOr<R>} promise - The promise function to be executed.
* @returns {Promise<[R | null, null | T]>} A promise that resolves to a tuple containing the result and error.
*/
const asyncHandler = async (promise) => {
try {
const data = await promise();
return [data, null];
}
catch (e) {
return [null, e];
}
};
exports.default = asyncHandler;