"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Strategy = exports.SlidingStrategy = exports.DroppingStrategy = void 0;
exports.dropppingStrategy = dropppingStrategy;
exports.slidingStrategy = slidingStrategy;

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

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

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

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/size"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/mutable/MutableQueue"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/unsafeGet"));

var tsplus_module_7 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/collections/Chunk/drop"));

var _unsafeCompleteTakers = /*#__PURE__*/require("@effect/core/io/Queue/operations/_internal/unsafeCompleteTakers");

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; }

const fileName_1 = "(@effect/core) _src/io/Queue/operations/strategy.ts";
const Strategy = {};
exports.Strategy = Strategy;

class DroppingStrategy {
  // Do nothing, drop the surplus
  handleSurplus(_as, _queue, _takers, _isShutdown, __tsplusTrace) {
    return tsplus_module_1.succeedNow(false, fileName_1 + ":40:29");
  }

  unsafeOnQueueEmptySpace(_queue) {//
  }

  get surplusSize() {
    return 0;
  }

  get shutdown() {
    return tsplus_module_2.unit;
  }

}

exports.DroppingStrategy = DroppingStrategy;

class SlidingStrategy {
  handleSurplus(as, queue, takers, _isShutdown, __tsplusTrace) {
    return tsplus_module_3.succeed(() => {
      this.unsafeSlidingOffer(queue, as);
      (0, _unsafeCompleteTakers.unsafeCompleteTakers)(this, queue, takers);
      return true;
    }, fileName_1 + ":64:26");
  }

  unsafeOnQueueEmptySpace(_queue) {//
  }

  get surplusSize() {
    return 0;
  }

  get shutdown() {
    return tsplus_module_2.unit;
  }

  unsafeSlidingOffer(queue, as) {
    let bs = as;

    while (tsplus_module_4.size(bs) > 0) {
      if (queue.capacity === 0) {
        return;
      } // Poll 1 and retry


      queue.poll(tsplus_module_5.EmptyMutableQueue);

      if (queue.offer(tsplus_module_6.unsafeGet_(bs, 0))) {
        bs = tsplus_module_7.drop_(bs, 1);
      }
    }
  }

}
/**
 * @tsplus static ets/QueueStrategy/Ops Sliding
 */


exports.SlidingStrategy = SlidingStrategy;

function slidingStrategy() {
  return new SlidingStrategy();
}
/**
 * @tsplus static ets/QueueStrategy/Ops Dropping
 */


function dropppingStrategy() {
  return new DroppingStrategy();
}
//# sourceMappingURL=strategy.js.map