source: trip-planner-front/node_modules/yargs/build/lib/utils/maybe-async-result.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 496 bytes
Line 
1import { isPromise } from './is-promise.js';
2export function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
3 throw err;
4}) {
5 try {
6 const result = isFunction(getResult) ? getResult() : getResult;
7 return isPromise(result)
8 ? result.then((result) => resultHandler(result))
9 : resultHandler(result);
10 }
11 catch (err) {
12 return errorHandler(err);
13 }
14}
15function isFunction(arg) {
16 return typeof arg === 'function';
17}
Note: See TracBrowser for help on using the repository browser.