import * as tsplus_module_1 from "@effect/core/io/Effect/operations/sleep";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/interruption";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/race";
/**
 * Returns an effect that will timeout this effect, returning either the
 * default value if the timeout elapses before the effect has produced a
 * value or returning the result of applying the function `f` to the
 * success value of the effect.
 *
 * If the timeout elapses without producing a value, the running effect will
 * be safely interrupted.
 *
 * @tsplus fluent ets/Effect timeoutTo
 */

export function timeoutTo_(self, def, f, duration, __tsplusTrace) {
  return tsplus_module_4.raceFirst_(tsplus_module_3.map_(self, f, __tsplusTrace), () => tsplus_module_3.map_(tsplus_module_2.interruptible(tsplus_module_1.sleep(duration, __tsplusTrace), __tsplusTrace), () => def(), __tsplusTrace), __tsplusTrace);
}
/**
 * Returns an effect that will timeout this effect, returning either the
 * default value if the timeout elapses before the effect has produced a
 * value or returning the result of applying the function `f` to the
 * success value of the effect.
 *
 * If the timeout elapses without producing a value, the running effect will
 * be safely interrupted.
 *
 * @tsplus static ets/Effect/Aspects timeoutTo
 */

export const timeoutTo = (def, f, duration, __tsplusTrace) => self => timeoutTo_(self, def, f, duration, __tsplusTrace);
//# sourceMappingURL=timeoutTo.mjs.map