Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streams: timeoutFirst #3728

Open
ryanleecode opened this issue Oct 3, 2024 · 0 comments
Open

Streams: timeoutFirst #3728

ryanleecode opened this issue Oct 3, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ryanleecode
Copy link

ryanleecode commented Oct 3, 2024

What is the problem this feature would solve?

a functionality similar to rxjs timeout({ first: number }) is missing.

What is the feature you are proposing to solve the problem?

import { Duration, pipe, Stream } from 'effect'
import type { LazyArg } from 'effect/Function'

export const timeoutFirstFail =
  <E2>(error: LazyArg<E2>, duration: Duration.DurationInput) => <A, E, R>(stream: Stream.Stream<A, E, R>) =>
    pipe(
      stream,
      Stream.broadcast(2, { capacity: 'unbounded' }),
      Stream.flatMap(([first, second]) =>
        Stream.merge(
          first.pipe(
            Stream.timeoutFail(
              error,
              duration,
            ),
            Stream.take(1),
            Stream.flatMap(() => Stream.empty),
          ),
          second,
          { haltStrategy: 'right' },
        )
      ),
    )

What alternatives have you considered?

No response

@ryanleecode ryanleecode added the enhancement New feature or request label Oct 3, 2024
@ryanleecode ryanleecode changed the title timeoutFirst Streams: timeoutFirst Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant