Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Currently we generate a lot of spurious fiber failure warnings. For example, consider:

ZIO.fail("fail").zipPar(ZIO.succeed("succeed")).foldCause(_ => 0, _ => 0)

This will succeed because foldCause recovers from all errors. But a fiber failure warning will still be printed to the console because one of the forked fibers in raceWith, which zipPar is implemented in terms of, ended in failure. This is undesirable in general and particularly confusing to new users who don't understand why the warning is displayed or that the success of their effect is independent of this warning.

This PR implements a new combinator forkInternal that forks an effect that will be executed without unhandled failures being reported. This can be use in combinators such as raceWith that implement their own logic for handling failures to avoid these spurious warnings being generated.

So far I have only used this in raceWith, which seems to be the cause of most of the spurious warnings that are being reported, but we should be able to use this in other combinators as well.

@adamgfraser adamgfraser requested a review from jdegoes October 11, 2019 03:46
mapM(f andThen UIO.succeed)

/**
* Effectually maps over the favlue the fiber computes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed now.

* Forks an effect that will be executed without unhandled failures being
* reported. This is useful for implementing combinators that handle failures
* themselves.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doc

ghostdogpr
ghostdogpr previously approved these changes Oct 11, 2019
/**
* Traverses the `Exit` with an effectual function.
*/
def traverse[R, E1 >: E, B](f: A => ZIO[R, E1, B]): ZIO[R, Nothing, Exit[E1, B]] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Let's add foreach alias too, if it doesn't exist.

* themselves.
*/
private[zio] final def forkInternal: ZIO[R, Nothing, Fiber[E, A]] =
run.fork.map(_.mapM(IO.done))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful!

jdegoes
jdegoes previously approved these changes Oct 13, 2019
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@adamgfraser adamgfraser dismissed stale reviews from jdegoes and ghostdogpr via 93f720f October 13, 2019 19:45
@adamgfraser adamgfraser merged commit 84159c1 into zio:master Oct 13, 2019
@adamgfraser adamgfraser deleted the fork branch October 13, 2019 20:06
ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request Nov 5, 2019
* implement forkInternal

* fix typo

* add foreach alias
Twizty pushed a commit to Twizty/zio that referenced this pull request Nov 13, 2019
* implement forkInternal

* fix typo

* add foreach alias
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.

4 participants