import { pipe } from "../Function"
import { succeed } from "./core"
import { die } from "./die"
import { effectAsync } from "./effectAsync"
import { fail } from "./fail"
/**
 * Create an Effect that when executed will construct `promise` and wait for its result,
 * errors will be handled using `onReject`
 */

export function tryCatchPromise(promise, onReject, __trace) {
  return effectAsync((resolve) => {
    promise()
      .then((x) => resolve(succeed(x)))
      .catch((x) => resolve(fail(onReject(x))))
  }, __trace)
}
/**
 * Create an Effect that when executed will construct `promise` and wait for its result,
 * errors will produce failure as `unknown`
 */

export function tryPromise(effect, __trace) {
  return effectAsync((resolve) => {
    effect()
      .then((x) => resolve(succeed(x)))
      .catch((x) => resolve(fail(x)))
  }, __trace)
}
/**
 * Like tryPromise but produces a defect in case of errors
 */

export function promise(effect, __trace) {
  return effectAsync((resolve) => {
    effect()
      .then((x) => resolve(succeed(x)))
      .catch((x) => resolve(die(x)))
  }, __trace)
}
//# sourceMappingURL=promise.js.map
