r37r0m0d3l/of

View on GitHub
src/core/ofOutcome.js

Summary

Maintainability
A
0 mins
Test Coverage
import { ofAnyCase } from "./ofAnyCase.js";

/**
 * @name ofOutcome
 * @description Returns result or thrown error wherever happens
 * @param {Function|Promise} callable
 * @param {*=} config
 * @returns {Promise<*>}
 */
export function ofOutcome(callable, config = {}) {
  return new Promise((resolve) =>
    ofAnyCase(callable, config).then(([result, error]) => {
      resolve(error ? error : result);
    }),
  );
}