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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cats Effect 1.0.0-RC #659

Merged
merged 12 commits into from May 1, 2018

Conversation

Projects
None yet
1 participant
@alexandru
Member

alexandru commented Apr 17, 2018

Updates Monix to Cats-Effect 1.0.0-RC.

I managed to produce another gigantic PR, not sure how I do it 馃檪 but many changes are superficial...

  1. introduced Platform.composeErrors for those cases in which, given multiple exceptions, we need to combine and signal multiple errors somehow聽鈥斅爐he logic is platform independent, as on top of the JVM we're using Throwable#addSuppressed, but on top of JavaScript we're simply returning a CompositeException
  2. modified StackFrame to no longer take an UncaughtExceptionHandler on error; this is a change to the internals of both Task and Coeval, as instead of reporting the error using a provided logger, we're now composing errors using Platform.composeErrors
  3. implemented bracket and bracketCase for Coeval, Task and Iterant
  4. Task now also implements the new Async#never; this posed difficulty in testing the new law, due to having to test for non-termination, which doesn't work well when we are testing Task#unsafeRunSync, so for those particular tests we're disabling the laws that test for non-termination
  5. for Coeval I added parens to .runTry() and .run() to signal side effects, which is a generally agreed upon convention in Scala; this doesn't have an impact on binary or source compatibility, other than warnings; many of the files enumerated as changed are due to this
  6. added redeem and redeemWith for Task and Coeval, as optimizations for attempt.map and attempt.flatMap respectively; see related issues: typelevel/cats#2237 and typelevel/cats-effect#191
  7. in Iterant deprecated the old Iterant.bracket, replacing it with Iterant.resource
  8. Iterant.resource relying on flatMap for use highlighted problems in Iterant#flatMap that were fixed
  9. Iterant#bracket and Iterant.resource are now implemented in terms of a new doOnExitCase operator; and the now deprecated Iterant.bracket is implemented in terms of Iterant.resource and flatMap
  10. Iterant.empty now returns the same reference, optimizing memory usage
  11. Iterant#dump was made more useful by printing the type of the node at each step ... this happened due to me debugging Iterant.resource(acquire)(release).flatMap(use), which was pretty hard
  12. the implementation for Iterant#doOnFinish is now gone, now being derived from doOnExitCase

So the new doOnExitCase for Iterant looks like this:

final def doOnExitCase(f: ExitCase[Throwable] => F[Unit])(implicit F: Sync[F]): Iterant[F, A] =
  IterantExitCallback.doOnExitCase(this, f) 

And then we can describe Iterant.resource:

  def resource[F[_], A](acquire: F[A])
    (release: A => F[Unit])
    (implicit F: Sync[F]): Iterant[F, A] = {

    suspendS(
      F.map(acquire) { a =>
        nextS[F, A](a, F.pure(Iterant.empty), F.unit)
          .doOnExitCase(_ => release(a))
      },
      F.unit)
  }

The deprecated Iterant.bracket:

  @deprecated("Use Iterant.resource", since="3.0.0-RC2")
  def bracket[F[_], A, B](acquire: F[A])
    (use: A => Iterant[F, B], release: A => F[Unit])
    (implicit F: Sync[F]): Iterant[F, B] =
    resource(acquire)(release).flatMap(use)

And the new Bracket implementation:

  final def bracketCase[B](use: A => Iterant[F, B])(release: (A, ExitCase[Throwable]) => Iterant[F, Unit])
    (implicit F: Sync[F]): Iterant[F, B] = {

    self.flatMap { a =>
      use(a).doOnExitCase(release(a, _).completeL)
    }
  }

Things left to do, but not addressed in this PR:

  1. Observable#doOnExitCase
  2. Observable.resource
  3. Iterant#cancelable as a way to address cancelation in F[_], see typelevel/cats-effect#192 (comment)
  4. Task violates the Concurrent and ConcurrentEffect laws when it is executed with the auto-cancelable run loop active and that's a big problem
  5. Task#bracket is broken in the presence of auto-cancelable run loops

alexandru added some commits Apr 16, 2018

@alexandru alexandru changed the title from WIP: Cats Effect 1.0-RC to Cats Effect 1.0.0-RC May 1, 2018

alexandru added some commits May 1, 2018

@codecov

This comment has been minimized.

codecov bot commented May 1, 2018

Codecov Report

Merging #659 into master will decrease coverage by 0.16%.
The diff coverage is 84.68%.

@@            Coverage Diff             @@
##           master     #659      +/-   ##
==========================================
- Coverage   91.03%   90.87%   -0.17%     
==========================================
  Files         377      377              
  Lines       10032    10089      +57     
  Branches     1887     1900      +13     
==========================================
+ Hits         9133     9168      +35     
- Misses        899      921      +22

@alexandru alexandru merged commit 711b2b8 into monix:master May 1, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment