fediversity.eu/node_modules/yargs/build/lib/utils/maybe-async-result.js

18 lines
496 B
JavaScript
Raw Normal View History

2024-03-26 16:28:28 +01:00
import { isPromise } from './is-promise.js';
export function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
throw err;
}) {
try {
const result = isFunction(getResult) ? getResult() : getResult;
return isPromise(result)
? result.then((result) => resultHandler(result))
: resultHandler(result);
}
catch (err) {
return errorHandler(err);
}
}
function isFunction(arg) {
return typeof arg === 'function';
}