r37r0m0d3l/of

View on GitHub
src/core/of.js

Summary

Maintainability
A
0 mins
Test Coverage
import { ERR_UNKNOWN } from "../const/error.js";

/**
 * @name of
 * @param {Promise} promise
 * @returns {Promise<[*, unknown] | [undefined, *]>}
 */
export function of(promise) {
  return Promise.resolve(promise)
    .then((result) => [result])
    .catch((caughtError) => {
      if (caughtError === undefined || caughtError === null) {
        caughtError = new Error(ERR_UNKNOWN);
      }
      return [undefined, caughtError];
    });
}