import * as tsplus_module_1 from "@effect/core/io/Effect/operations/unit";
import * as tsplus_module_2 from "@effect/core/stream/Stream/operations/runForEachScoped";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/catchAllCause";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/forkScoped";
import * as tsplus_module_5 from "@effect/core/stream/Stream/operations/scoped";
import * as tsplus_module_6 from "@effect/core/stream/Stream/operations/interruptWhenDeferred";
import * as tsplus_module_7 from "@effect/core/stream/Stream/operations/crossRight";
import * as tsplus_module_8 from "@effect/core/io/Deferred/operations/make";
import * as tsplus_module_9 from "@effect/core/stream/Stream/operations/fromEffect";
import * as tsplus_module_10 from "@effect/core/stream/Stream/operations/flatMap";
/**
 * Drains the provided stream in the background for as long as this stream is
 * running. If this stream ends before `other`, `other` will be interrupted.
 * If `other` fails, this stream will fail with that error.
 *
 * @tsplus fluent ets/Stream drainFork
 */

export function drainFork_(self, other, __tsplusTrace) {
  return tsplus_module_10.flatMap_(tsplus_module_9.fromEffect(() => tsplus_module_8.make(__tsplusTrace), __tsplusTrace), backgroundDied => tsplus_module_7.crossRight_(tsplus_module_5.scoped(() => tsplus_module_4.forkScoped(tsplus_module_3.catchAllCause_(tsplus_module_2.runForEachScoped_(other(), () => tsplus_module_1.unit, __tsplusTrace), cause => backgroundDied.failCause(() => cause, __tsplusTrace), __tsplusTrace), __tsplusTrace), __tsplusTrace), () => tsplus_module_6.interruptWhenDeferred_(self, () => backgroundDied, __tsplusTrace), __tsplusTrace), __tsplusTrace);
}
/**
 * Drains the provided stream in the background for as long as this stream is
 * running. If this stream ends before `other`, `other` will be interrupted.
 * If `other` fails, this stream will fail with that error.
 *
 * @tsplus static ets/Stream/Aspects drainFork
 */

export const drainFork = (other, __tsplusTrace) => self => drainFork_(self, other, __tsplusTrace);
//# sourceMappingURL=drainFork.mjs.map