8
import {isPromise} from './is-promise.js';
9
export function maybeAsyncResult<T>(
11
>
resultHandler: (result: T) => T | Promise<T>,
12
>
errorHandler: (err: Error) => T = (err: Error) => {
13
throw err;
14
}
16
>
try {
17
>
const result = isFunction(getResult) ? getResult() : getResult;
18
>
return isPromise(result)
19
>
? result.then((result: T) => resultHandler(result))
20
>
: resultHandler(result);
21
>
} catch (err) {
22
return errorHandler(err as Error);
23
}
25
27
>
return typeof arg === 'function';
28
>
}