import * as tsplus_module_1 from "@effect/core/io/Effect/operations/intoDeferred";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/catchAllCause";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/fork";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/zipRight";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/interruption";
import * as tsplus_module_6 from "@effect/core/io/Effect/operations/runtime";
import * as tsplus_module_7 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_8 from "@effect/core/io/Deferred/operations/make";
/**
 * Imports an asynchronous effect into a pure `Effect` value. This formulation
 * is necessary when the effect is itself expressed in terms of an `Effect`.
 *
 * @tsplus static ets/Effect/Ops asyncEffect
 */

export function asyncEffect(register, __tsplusTrace) {
  return tsplus_module_7.flatMap_(tsplus_module_8.make(__tsplusTrace), deferred => tsplus_module_7.flatMap_(tsplus_module_6.runtime(__tsplusTrace), runtime => tsplus_module_5.uninterruptibleMask(({
    restore
  }) => tsplus_module_4.zipRight_(tsplus_module_3.fork(restore(() => tsplus_module_2.catchAllCause_(register(k => runtime.unsafeRunAsync(tsplus_module_1.intoDeferred_(k, () => deferred, __tsplusTrace), __tsplusTrace)), cause => deferred.failCause(() => cause, __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace), () => restore(() => deferred.await(__tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=asyncEffect.mjs.map