Skip to content
New issue

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

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

Already on GitHub? # to your account

Stream#translate forgets ability to interrupt effect evaluation #1443

Closed
mpilquist opened this issue Apr 11, 2019 · 3 comments
Closed

Stream#translate forgets ability to interrupt effect evaluation #1443

mpilquist opened this issue Apr 11, 2019 · 3 comments

Comments

@mpilquist
Copy link
Member

One thing I recently noticed is that Stream#translate doesn't take a Concurrent[G] anymore, which seems like an oversight to me. For example:

@ val s = Stream.eval(IO.never).merge(Stream.eval(IO(1)).repeat)
s: Stream[IO[x], Int] = Stream(..)

@ s.interruptAfter(1.second).compile.drain.unsafeRunSync
// Returns after 1 second

@ s.interruptAfter(1.second).translate(cats.arrow.FunctionK.id[IO]).compile.drain.unsafeRunSync
// Hangs

The interpreter uses the Concurrent instance to interrupt effect evaluation. When we translate with the identity FunctionK, the interpreter forgets about the old Concurrent[IO] it had.

The "right" fix with the 1.0 design is changing the signature of translate to take an Option[Concurrent[G]], but then this breaks mapK (and binary compatibility).

Another option is documenting the limitations of translate and adding a translateConcurrent overload that takes an implicit Concurrent[G].

@SystemFw
Copy link
Collaborator

I don't think it's an oversight, didn't we do it to support ConnectionIO at some point?

@mpilquist
Copy link
Member Author

The TranslateInterrupt typeclass has two implicit constructors but we only ever use the fallback one. I think we might want a method like translateInterruptible that takes a Concurrent instance

@SystemFw
Copy link
Collaborator

I think we might want a method like translateInterruptible

sounds reasonable given current constraints

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants