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

Make interruptWhen a no-op with the Sync compiler #2657

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

rossabaker
Copy link
Member

Addresses #2371. Solution first discussed in #2650.

Before, compiling a concurrent stream with the Sync compiler would fail quickly and pessimistically. Now we proceed with no-op interruption. We can now successfully process more streams with this compiler at the expense of non-termination of some.

This is helpful when constraining to Sync when Async would have brought a more powerful compiler, or translating a Concurrent stream to a Synchronous effect like Doobie's ConnectionIO.

@rossabaker
Copy link
Member Author

I'm trying to understand the subtle ways Sync and Concurrent compilers might diverge. I'm surprised this test fails: I thought if interruptWhen isn't processed, the left would not be interrupted and still emit the 1. Instead, we get Nil. I'm not disappointed that it behaves more like Concurrent, but I'm confused.

    Deferred[IO, Unit].flatMap { rightHalt =>
      val left = Stream.eval(rightHalt.get).drain ++ Stream.sleep[IO](100.millis) ++ Stream.emit(1)
      val right = Stream.eval(rightHalt.complete(())).drain
      compileWithSync(left.mergeHaltBoth(right)).toList
    }.assertEquals(List(1))

@mpilquist mpilquist merged commit 4403401 into typelevel:main Oct 1, 2021
@mpilquist
Copy link
Member

@rossabaker That one works b/c merge internally compiles and runs both streams. Hence, the compilation of the internal left/right is using the Concurrent instance picked up from merge.

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.

None yet

2 participants