Skip to content

Document scope limitations of concurrent Stream combinators#3676

Open
reardonj wants to merge 1 commit intotypelevel:mainfrom
reardonj:issue-3076-par-scope-propagation
Open

Document scope limitations of concurrent Stream combinators#3676
reardonj wants to merge 1 commit intotypelevel:mainfrom
reardonj:issue-3076-par-scope-propagation

Conversation

@reardonj
Copy link

@reardonj reardonj commented Feb 7, 2026

  • add general documentation to Stream warning about scopes not extending through operations that use Concurrent
  • add specific documentation for the couple of methods that are safe

I've taken a stab at documenting the current behavior instead of trying to fix #3076 given how intractable fixing that bug has been.

I ran variations of this code with various combinators to see what the full scope of the problem is:

Deferred[IO, Unit]
      .flatMap { d =>
        Stream
          .bracket(IO.unit)(_ => d.complete(()).void)
          .prefetch
          .evalMap(_ => IO.sleep(1.second) >> d.complete(()))
          .timeout(5.seconds)
          .compile
          .last
      }

Unfortunately, scopes don't seem to propagate for basically any combinator requiring a Concurrent instance. More specifically, these are generally passing stream elements through channels to a concurrently running stream, and the scopes of the original stream aren't held open until the background stream completes.

- add general documentation to Stream warning about scopes not extending through operations that use `Concurrent`
- add specific documentation for the couple of methods that are safe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parEvalMap* runs resource finaliser before usage

1 participant