"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withCleanup = withCleanup;
/** @internal */
function withCleanup(item, cleanup) {
    return {
        ...item,
        [Symbol.dispose]() {
            cleanup(item);
            // if `item` already has a cleanup function, we also need to call the original cleanup function
            // (e.g. if something is wrapped in `withCleanup` twice)
            if (Symbol.dispose in item) {
                item[Symbol.dispose]();
            }
        },
    };
}
//# sourceMappingURL=withCleanup.cjs.map
