import { pipe } from "../../Function";
import * as Q from "../../Queue";
import * as T from "../_internal/effect";
import * as M from "../_internal/managed";
import { bufferSignal } from "./_internal/bufferSignal";
import { Stream } from "./definitions";
/**
 * Allows a faster producer to progress independently of a slower consumer by buffering
 * up to `capacity` elements in a sliding queue.
 *
 * @note Prefer capacities that are powers of 2 for better performance.
 */

export function bufferSliding_(self, capacity) {
  return new Stream(M.chain_(M.bind_(M.do, "queue", () => T.toManagedRelease_(Q.makeSliding(capacity), Q.shutdown)), ({
    queue
  }) => bufferSignal(self, queue)));
}
/**
 * Allows a faster producer to progress independently of a slower consumer by buffering
 * up to `capacity` elements in a sliding queue.
 *
 * @note Prefer capacities that are powers of 2 for better performance.
 */

export function bufferSliding(capacity) {
  return self => bufferSliding_(self, capacity);
}
//# sourceMappingURL=bufferSliding.js.map