"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.ensuringChild =
  exports.ensuringChild_ =
  exports.ensuringChildren_ =
  exports.ensuringChildren =
    void 0
const Fiber = __importStar(require("../Fiber"))
const Function_1 = require("../Function")
const Supervisor_1 = require("../Supervisor")
const core = __importStar(require("./core"))
const ensuring = __importStar(require("./ensuring"))
/**
 * Acts on the children of this fiber, guaranteeing the specified callback
 * will be invoked, whether or not this effect succeeds.
 *
 * @dataFirst ensuringChildren_
 */
function ensuringChildren(children, __trace) {
  return (fa) => ensuringChildren_(fa, children, __trace)
}
exports.ensuringChildren = ensuringChildren
/**
 * Acts on the children of this fiber, guaranteeing the specified callback
 * will be invoked, whether or not this effect succeeds.
 */
function ensuringChildren_(fa, children, __trace) {
  return core.chain_(Supervisor_1.track, (s) =>
    ensuring.ensuring_(core.supervised_(fa, s), core.chain_(s.value, children), __trace)
  )
}
exports.ensuringChildren_ = ensuringChildren_
/**
 * Acts on the children of this fiber (collected into a single fiber),
 * guaranteeing the specified callback will be invoked, whether or not
 * this effect succeeds.
 */
function ensuringChild_(fa, f, __trace) {
  return ensuringChildren_(fa, (x) => f(Fiber.collectAll(x)), __trace)
}
exports.ensuringChild_ = ensuringChild_
/**
 * Acts on the children of this fiber (collected into a single fiber),
 * guaranteeing the specified callback will be invoked, whether or not
 * this effect succeeds.
 *
 * @dataFirst ensuringChild_
 */
function ensuringChild(f, __trace) {
  return (fa) => ensuringChild_(fa, f, __trace)
}
exports.ensuringChild = ensuringChild
//# sourceMappingURL=ensuringChildren.js.map
