"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromHubManagedWithShutdown = exports.fromHubManagedWithShutdown_ = void 0;
// ets_tracing: off
const H = __importStar(require("../../../../Hub"));
const M = __importStar(require("../../../../Managed"));
const C = __importStar(require("../core"));
const Ensuring = __importStar(require("./ensuring"));
const FromHubManaged = __importStar(require("./fromHubManaged"));
/**
 * Creates a stream from a subscription to a hub in the context of a managed
 * effect. The managed effect describes subscribing to receive messages from
 * the hub while the stream describes taking messages from the hub.
 *
 * The hub will be shut down once the stream is closed.
 */
function fromHubManagedWithShutdown_(hub, maxChunkSize = C.DEFAULT_CHUNK_SIZE) {
    return M.map_(FromHubManaged.fromHubManaged_(hub, maxChunkSize), Ensuring.ensuring(H.shutdown(hub)));
}
exports.fromHubManagedWithShutdown_ = fromHubManagedWithShutdown_;
/**
 * Creates a stream from a subscription to a hub in the context of a managed
 * effect. The managed effect describes subscribing to receive messages from
 * the hub while the stream describes taking messages from the hub.
 *
 * The hub will be shut down once the stream is closed.
 *
 * @ets_data_first fromHubManagedWithShutdown_
 */
function fromHubManagedWithShutdown(maxChunkSize = C.DEFAULT_CHUNK_SIZE) {
    return (hub) => fromHubManagedWithShutdown_(hub, maxChunkSize);
}
exports.fromHubManagedWithShutdown = fromHubManagedWithShutdown;
//# sourceMappingURL=fromHubManagedWithShutdown.js.map