-
Couldn't load subscription status.
- Fork 1.4k
Implement ZIO#forkInternal #4142
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
Conversation
|
|
||
| val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope) | ||
| val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope) | ||
| val left = fork(race.left.asInstanceOf[IO[EL, A]].traced.run.untraced, race.scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will add a lot of performance overhead to such a low level operation. Any way to cheat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tracing or the running? The tracing probably yes. The running will I think require some changes in FiberContext but I think they can be relatively straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at this version. Should be more efficient.
| val value: ZIO[R, E, A], | ||
| val scope: Option[ZScope[Exit[Any, Any]]] | ||
| val scope: Option[ZScope[Exit[Any, Any]]], | ||
| val reportFailure: Option[Cause[Any] => Unit] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an additional field here is a binary incompatible change even though this is package private. We could potentially revert and use the previous implementation of forkInternal for everything except the raceWith implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe to mark as an exclusion I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so too. Will do.
| val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope) | ||
| val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope) | ||
| val left = fork[EL, A](race.left.asInstanceOf[IO[EL, A]], race.scope, Some(_ => ())) | ||
| val right = fork[ER, B](race.right.asInstanceOf[IO[ER, B]], race.scope, Some(_ => ())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factor out Some(_ => ()) into a constant of FiberContext companion object.
Resolves #4136.
We had actually resolved this issue previously in #1949 but removed it when we stopped logging pure interruptions, which inadvertently caused a regression because fiber failures other than interruption can subsequently be handled at a higher level of the application.
The basic problem here is that a fiber doesn't know who will join it or what they will do once joining it, so a fiber has to either report the error or not. Thus, when we fork a fiber if we intend to handle its errors ourselves we need to signal to the fiber that it does not need to log fiber failures. We can do this with calling
runon the effect we are forking and then usingflatMap(IO.done(_))to flatten the exit value back into an effect. The implementation inraceWithis slightly more complicated now that it has been moved intoFiberContextbut conceptually the same.I explored an alternative solution where we pushed more of this logic into
FiberContextand eachFiberContexthad an error handler that could be overridden that we could explore if we wanted.