import * as tsplus_module_1 from "@effect/core/io/Effect/operations/failNow";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/succeedNow";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/async";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/succeed";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/dieNow";
/**
 * Create an `Effect` that when executed will construct `promise` and wait for
 * its result, errors will be handled using `onReject`.
 *
 * @tsplus static ets/Effect/Ops tryCatchPromise
 */

export function tryCatchPromise(promise, onReject, __tsplusTrace) {
  return tsplus_module_5.flatMap_(tsplus_module_4.succeed(promise, __tsplusTrace), promise => tsplus_module_3._async(resolve => {
    promise.then(a => resolve(tsplus_module_2.succeedNow(a, __tsplusTrace))).catch(e => resolve(tsplus_module_1.failNow(onReject(e), __tsplusTrace)));
  }, __tsplusTrace), __tsplusTrace);
}
/**
 * Create an `Effect` that when executed will construct `promise` and wait for
 * its result, errors will produce failure as `unknown`.
 *
 * @tsplus static ets/Effect/Ops tryPromise
 */

export function tryPromise(promise, __tsplusTrace) {
  return tsplus_module_5.flatMap_(tsplus_module_4.succeed(promise, __tsplusTrace), promise => tsplus_module_3._async(resolve => {
    promise.then(a => resolve(tsplus_module_2.succeedNow(a, __tsplusTrace))).catch(e => resolve(tsplus_module_1.failNow(e, __tsplusTrace)));
  }, __tsplusTrace), __tsplusTrace);
}
/**
 * Like `tryPromise` but produces a defect in case of errors.
 *
 * @tsplus static ets/Effect/Ops promise
 */

export function promise(promise, __tsplusTrace) {
  return tsplus_module_5.flatMap_(tsplus_module_4.succeed(promise, __tsplusTrace), promise => tsplus_module_3._async(resolve => {
    promise.then(a => resolve(tsplus_module_2.succeedNow(a, __tsplusTrace))).catch(e => resolve(tsplus_module_6.dieNow(e, __tsplusTrace)));
  }, __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=promise.mjs.map