Skip to content

Add CancellableEffect typeclass. Use it to give races to IO#984

Merged
pakoito merged 43 commits into
masterfrom
paco-ioraces
Sep 15, 2018
Merged

Add CancellableEffect typeclass. Use it to give races to IO#984
pakoito merged 43 commits into
masterfrom
paco-ioraces

Conversation

@pakoito
Copy link
Copy Markdown
Member

@pakoito pakoito commented Aug 11, 2018

This PR races two IOs, allowing cancellation between them.

It also adds the typeclass CancellableEffect, that was needed to achieve this.

@pakoito pakoito requested review from a team and raulraja August 11, 2018 02:34
@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 12, 2018

Codecov Report

Merging #984 into master will decrease coverage by 0.63%.
The diff coverage is 43.95%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master    #984      +/-   ##
===========================================
- Coverage     47.03%   46.4%   -0.64%     
+ Complexity      694     692       -2     
===========================================
  Files           320     320              
  Lines          8091    8255     +164     
  Branches        848     859      +11     
===========================================
+ Hits           3806    3831      +25     
- Misses         3942    4080     +138     
- Partials        343     344       +1
Impacted Files Coverage Δ Complexity Δ
...s-rx2/src/main/kotlin/arrow/effects/ObservableK.kt 61.53% <0%> (-6.55%) 9 <0> (ø)
...cts-rx2/src/main/kotlin/arrow/effects/FlowableK.kt 50.63% <0%> (-3.43%) 9 <0> (ø)
...fects-rx2/src/main/kotlin/arrow/effects/SingleK.kt 73.33% <0%> (-14.67%) 6 <0> (ø)
...-test/src/main/kotlin/arrow/test/laws/MonadLaws.kt 48.33% <0%> (ø) 12 <1> (ø) ⬇️
...rc/main/kotlin/arrow/effects/FlowableKInstances.kt 57.14% <0%> (-2.12%) 0 <0> (ø)
.../src/main/kotlin/arrow/effects/SingleKInstances.kt 70% <0%> (-3.69%) 0 <0> (ø)
.../main/kotlin/arrow/effects/ObservableKInstances.kt 55.55% <0%> (-2.14%) 0 <0> (ø)
...rc/main/kotlin/arrow/effects/DeferredKInstances.kt 68.18% <0%> (-3.25%) 0 <0> (ø)
...effects/src/main/kotlin/arrow/effects/IORunLoop.kt 73.79% <100%> (-1.07%) 45 <0> (-2)
...w/effects/data/internal/IOCancellationException.kt 100% <100%> (ø) 1 <1> (ø) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f0c3c0...134c6c4. Read the comment docs.

@pakoito pakoito changed the title [WIP] Add race to IO Add CancellableEffect typeclass. Use it to give races to IO Sep 1, 2018
@pakoito
Copy link
Copy Markdown
Member Author

pakoito commented Sep 1, 2018

@raulraja ready for review!

}
}

fun <A, B, C, D> IO.Companion.raceN(ctx: CoroutineContext, a: IO<A>, b: IO<B>, c: IO<C>, d: IO<D>): IO<Either<Either<A, B>, Either<C, D>>> =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hoping these would make it to a Concurrent type class in the near future.

import arrow.Kind
import arrow.core.Either

interface CancellableEffect<F> : Effect<F> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this should be just Concurrent and include the race style algebra combinators in this type class so they are available for all concurrent effects in the spirit that concurrent effects are cancelable. For what is worth in cats we have:

Concurrent[F] extends Async[F]
ConcurrentEffect[F] extends Concurrent[F] with Effect[F]

Copy link
Copy Markdown
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

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

This is definitely an improvement from what we have but I'm missing the type class aspect of race, etc.. which should live in my opinion in Concurrent just above Async in a similar way to how it's done in cats-effect

@pakoito pakoito merged commit ea2f788 into master Sep 15, 2018
@pakoito pakoito deleted the paco-ioraces branch September 15, 2018 21:58
@pakoito pakoito mentioned this pull request Oct 11, 2018
7 tasks
@raulraja raulraja mentioned this pull request Nov 2, 2018
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.

2 participants