"use strict"
Object.defineProperty(exports, "__esModule", { value: true })
exports.forkWithErrorHandler_ = exports.forkWithErrorHandler = void 0
// tracing: off
const Cause_1 = require("../Cause")
const Either_1 = require("../Either")
const Function_1 = require("../Function")
const core_1 = require("./core")
const onExit_1 = require("./onExit")
/**
 * Like fork but handles an error with the provided handler.
 *
 * @dataFirst forkWithErrorHandler_
 */
function forkWithErrorHandler(handler, __trace) {
  return (self) => forkWithErrorHandler_(self, handler, __trace)
}
exports.forkWithErrorHandler = forkWithErrorHandler
/**
 * Like fork but handles an error with the provided handler.
 */
function forkWithErrorHandler_(self, handler, __trace) {
  return (0, core_1.fork)(
    (0, onExit_1.onError_)(self, (x) =>
      (0, Either_1.fold)(handler, core_1.halt)((0, Cause_1.failureOrCause)(x))
    ),
    __trace
  )
}
exports.forkWithErrorHandler_ = forkWithErrorHandler_
//# sourceMappingURL=forkWithErrorHandler.js.map
