"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.raceWith = void 0;
exports.raceWith_ = raceWith_;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/done"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/MergeDecision"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/mergeWith"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/pipeTo"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/toHub"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Channel/operations/fromHubScoped"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Hub/operations/bounded"));

var tsplus_module_8 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/do"));

var tsplus_module_9 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/map"));

var tsplus_module_10 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/stream/Sink/operations/unwrapScoped"));

var _SinkInternal = /*#__PURE__*/require("@effect/core/stream/Sink/operations/_internal/SinkInternal");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * 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
 */
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.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
 */


const raceWith = (that, leftDone, rightDone, capacity = 16, __tsplusTrace) => self => raceWith_(self, that, leftDone, rightDone, capacity, __tsplusTrace);

exports.raceWith = raceWith;
//# sourceMappingURL=raceWith.js.map