import * as tsplus_module_1 from "@effect/core/io/Effect/operations/done";
import * as tsplus_module_2 from "@effect/core/stream/Channel/MergeDecision";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/mergeWith";
import * as tsplus_module_4 from "@effect/core/stream/Channel/operations/pipeTo";
import * as tsplus_module_5 from "@effect/core/stream/Channel/operations/toHub";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/fromHubScoped";
import * as tsplus_module_7 from "@effect/core/io/Hub/operations/bounded";
import * as tsplus_module_8 from "@effect/core/io/Effect/operations/do";
import * as tsplus_module_9 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_10 from "@effect/core/stream/Sink/operations/unwrapScoped";
import { concreteSink, SinkInternal } from "@effect/core/stream/Sink/operations/_internal/SinkInternal";
/**
 * Runs both sinks in parallel on the input, using the specified merge
 * function as soon as one result or the other has been computed.
 *
 * @tsplus fluent ets/Sink raceWith
 */

export function raceWith_(self, that, leftDone, rightDone, capacity = 16, __tsplusTrace) {
  return tsplus_module_10.unwrapScoped(() => tsplus_module_9.map_(tsplus_module_8.bindValue_(tsplus_module_8.bindValue_(tsplus_module_8.bindValue_(tsplus_module_8.bind_(tsplus_module_8.bind_(tsplus_module_8.bind_(tsplus_module_8.Do(), "hub", () => tsplus_module_7.bounded(capacity, __tsplusTrace), __tsplusTrace), "c1", ({
    hub
  }) => tsplus_module_6.fromHubManaged(hub), __tsplusTrace), "c2", ({
    hub
  }) => tsplus_module_6.fromHubManaged(hub), __tsplusTrace), "reader", ({
    hub
  }) => tsplus_module_5.toHub(() => hub), __tsplusTrace), "writer", ({
    c1,
    c2
  }) => {
    const that0 = that();
    void 0;
    void 0;
    return tsplus_module_3.mergeWith_(tsplus_module_4.pipeTo_(c1, () => self.channel), () => tsplus_module_4.pipeTo_(c2, () => that0.channel), leftDone, rightDone);
  }, __tsplusTrace), "channel", ({
    reader,
    writer
  }) => tsplus_module_3.mergeWith_(reader, () => writer, () => tsplus_module_2._await(exit => tsplus_module_1.done(() => exit, __tsplusTrace)), done => tsplus_module_2.done(tsplus_module_1.done(() => done, __tsplusTrace))), __tsplusTrace), ({
    channel
  }) => new SinkInternal(channel), __tsplusTrace), __tsplusTrace);
}
/**
 * Runs both sinks in parallel on the input, using the specified merge
 * function as soon as one result or the other has been computed.
 *
 * @tsplus static ets/Sink/Aspects raceWith
 */

export const raceWith = (that, leftDone, rightDone, capacity = 16, __tsplusTrace) => self => raceWith_(self, that, leftDone, rightDone, capacity, __tsplusTrace);
//# sourceMappingURL=raceWith.mjs.map