export const StreamTimeoutErrorSym = Symbol.for( "@effect/core/stream/Stream/StreamTimeoutError" ) export class StreamTimeoutError { readonly [StreamTimeoutErrorSym] = "StreamTimeoutError" constructor(readonly message?: string) {} } export function isStreamTimeoutError(u: unknown): u is StreamTimeoutError { return ( u instanceof StreamTimeoutError && u[StreamTimeoutErrorSym] === "StreamTimeoutError" ) } /** * Switches the stream if it does not produce a value after the spcified * duration. * * @tsplus static effect/core/stream/Stream.Aspects timeoutTo * @tsplus pipeable effect/core/stream/Stream timeoutTo */ export function timeoutTo(duration: Duration, that: Stream) { return (self: Stream): Stream => self .timeoutFailCause(Cause.die(new StreamTimeoutError()), duration) .catchSomeCause((cause) => cause.isDieType() && isStreamTimeoutError(cause.value) ? Maybe.some(that) : Maybe.none ) }