var _a; // ets_tracing: off


import * as C from "../../Cause";
import { pipe } from "../../Function";
import * as O from "../../Option";
import { catchSome } from "./catchSome";
import { timeoutErrorCause } from "./timeoutErrorCause";
export const StreamTimeoutSymbol = /*#__PURE__*/Symbol.for("@matechs/core/Stream/Stream/timeoutTo/StreamTimeout");
export class StreamTimeoutError extends Error {
  constructor(message) {
    super(message);
    this[_a] = "StreamTimeoutError";
    this.name = this[StreamTimeoutSymbol];
  }

}
_a = StreamTimeoutSymbol;
export const isStreamTimeout = u => u instanceof Error && u[StreamTimeoutSymbol] === "StreamTimeoutError";
/**
 * Switches the stream if it does not produce a value after d duration.
 */

export function timeoutTo(d) {
  return that => self => catchSome(e => {
    if (isStreamTimeout(e)) {
      return O.some(that);
    }

    return O.none;
  })(timeoutErrorCause(C.die(new StreamTimeoutError()))(d)(self));
}
//# sourceMappingURL=timeoutTo.js.map