"use strict"
Object.defineProperty(exports, "__esModule", { value: true })
exports.join =
  exports.interruptStatus =
  exports.uninterruptible =
  exports.interruptible =
  exports.InterruptStatus =
  exports.Synthetic =
  exports.Descriptor =
  exports.None =
  exports.newFiberId =
  exports.FiberID =
  exports.equalsFiberID =
    void 0
// tracing: off
const core_1 = require("../Effect/core")
const done_1 = require("../Effect/done")
const tap_1 = require("../Effect/tap")
var id_1 = require("./id")
Object.defineProperty(exports, "equalsFiberID", {
  enumerable: true,
  get: function () {
    return id_1.equalsFiberID
  }
})
Object.defineProperty(exports, "FiberID", {
  enumerable: true,
  get: function () {
    return id_1.FiberID
  }
})
Object.defineProperty(exports, "newFiberId", {
  enumerable: true,
  get: function () {
    return id_1.newFiberId
  }
})
Object.defineProperty(exports, "None", {
  enumerable: true,
  get: function () {
    return id_1.None
  }
})
/**
 * A record containing information about a `Fiber`.
 *
 * @param id            The fiber's unique identifier
 * @param interruptors  The set of fibers attempting to interrupt the fiber or its ancestors.
 * @param children      The fiber's forked children.
 */
class Descriptor {
  constructor(id, status, interruptors, interruptStatus, scope) {
    this.id = id
    this.status = status
    this.interruptors = interruptors
    this.interruptStatus = interruptStatus
    this.scope = scope
  }
}
exports.Descriptor = Descriptor
class Synthetic {
  constructor(_await, getRef, inheritRefs, interruptAs, poll) {
    this.getRef = getRef
    this.inheritRefs = inheritRefs
    this.interruptAs = interruptAs
    this.poll = poll
    this._tag = "SyntheticFiber"
    this.await = _await
  }
}
exports.Synthetic = Synthetic
/**
 * InterruptStatus tracks interruptability of the current stack region
 */
class InterruptStatus {
  constructor(isInterruptible) {
    this.isInterruptible = isInterruptible
  }
  get isUninteruptible() {
    return !this.isInterruptible
  }
  get toBoolean() {
    return this.isInterruptible
  }
}
exports.InterruptStatus = InterruptStatus
/**
 * Interruptible region
 */
exports.interruptible = new InterruptStatus(true)
/**
 * Uninterruptible region
 */
exports.uninterruptible = new InterruptStatus(false)
/**
 * Create InterruptStatus from a boolean value
 */
const interruptStatus = (b) => (b ? exports.interruptible : exports.uninterruptible)
exports.interruptStatus = interruptStatus
/**
 * Joins the fiber, which suspends the joining fiber until the result of the
 * fiber has been determined. Attempting to join a fiber that has erred will
 * result in a catchable error. Joining an interrupted fiber will result in an
 * "inner interruption" of this fiber, unlike interruption triggered by another
 * fiber, "inner interruption" can be caught and recovered.
 */
function join(fiber) {
  return (0, tap_1.tap_)(
    (0, core_1.chain_)(fiber.await, done_1.done),
    () => fiber.inheritRefs
  )
}
exports.join = join
//# sourceMappingURL=core.js.map
