import * as tsplus_module_1 from "@effect/core/stream/Stream/operations/fromHub";
import * as tsplus_module_2 from "@effect/core/stream/Stream/operations/ensuring";
import * as tsplus_module_3 from "@effect/core/stream/Stream/operations/succeed";
import * as tsplus_module_4 from "@effect/core/stream/Stream/operations/flatMap";
import { DEFAULT_CHUNK_SIZE } from "@effect/core/stream/Stream/definition";
/**
 * Creates a stream from a subscription to a hub.
 *
 * The hub will be shut down once the stream is closed.
 *
 * @param maxChunkSize
 *   Maximum number of queued elements to put in one chunk in the stream.
 *
 * @tsplus static ets/Stream/Ops fromHubWithShutdown
 */

export function fromHubWithShutdown(hub, maxChunkSize = DEFAULT_CHUNK_SIZE, __tsplusTrace) {
  return tsplus_module_4.flatMap_(tsplus_module_3.succeed(hub, __tsplusTrace), hub => tsplus_module_2.ensuring_(tsplus_module_1.fromHub(() => hub, maxChunkSize, __tsplusTrace), () => hub.shutdown, __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=fromHubWithShutdown.mjs.map