Skip to content
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

[WIP] Add cats.Parallel instance for Future #132

Merged
merged 2 commits into from
Aug 23, 2019

Conversation

felixbr
Copy link
Contributor

@felixbr felixbr commented Jul 17, 2019

Hi,

this is a first attempt at adding a cats.Parallel instance (see #90).

Since I'm mostly familiar with Future and not Rerunnable I implemented it for Future first and if that is done I can maybe try to replicate it for Rerunnable.

I based the implementation on the implementations for cats.effect.IO and monix.eval.Task as I know those libraries reasonably well.

I consider this PR WIP as I have some questions:

  1. I reused the Newtype concept present in cats-effect and monix. Both have an Apache2.0 license, so I'm not sure how attribution for this piece of code works. Maybe we can just use it, maybe we need to keep the copyright header, I'm not too familiar how this works, sorry.

  2. I put the tests next to the existing ones for Future. As ArbitraryInstances doesn't have FuturePar in scope I couldn't move the instances there. For the moment they are in the FutureSuite, but if you don't like this I can put more time into finding a scoping solution to extract it.

  3. The elephant in the room is the fact that ap and product on the normal Future instance are already defined in terms of Future.join, so they run things in parallel already. This means traverse and parTraverse as well as sequence and parSequence will all be parallel. This is in line with the behavior of instances of scala.concurrent.Future iirc.
    There is the option to change traverse to be sequential, but sequence cannot be sequential (afaik), so this would be awkward and besides that it'd also be a breaking change.
    I'd argue that parTraverse and parSequence still have the benefit of explicitly signaling the reader how they will execute, even if they don't necessarily bring new functionality to the table.

Hope this is reasonable. Looking forward to your feedback :)

Cheers
~ Felix

@felixbr
Copy link
Contributor Author

felixbr commented Jul 17, 2019

So travis-ci says Expected feature release number in range of 9 to 14, but got: 8.

I'm not familiar with your workflow here, so if I need to PR on something other than master or increment the release number somewhere, you'll have to tell me.

@travisbrown
Copy link
Contributor

@felixbr I think that's a Travis CI JVM thing—they've been phasing out Oracle JDK 8 and I guess it hadn't hit this repo before now. If you change the Travis config to openjdk8 it should work.

@travisbrown
Copy link
Contributor

(I'll review tomorrow—thanks for doing this!)

@codecov-io
Copy link

codecov-io commented Jul 17, 2019

Codecov Report

Merging #132 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #132     +/-   ##
=========================================
+ Coverage    93.8%   93.91%   +0.1%     
=========================================
  Files           4        5      +1     
  Lines         113      115      +2     
  Branches        3        3             
=========================================
+ Hits          106      108      +2     
  Misses          7        7
Impacted Files Coverage Δ
...main/scala/io/catbird/util/internal/Newtype1.scala 100% <100%> (ø)

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 f975e60...81bd263. Read the comment docs.

@travisbrown
Copy link
Contributor

Sorry, lost track of this…


/** INTERNAL API — Newtype encoding for types with one type parameter.
*
* The `Newtype1` abstract class indirection is needed for Scala 2.10,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't support 2.10, so couldn't these go directly on FuturePar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll take a look at it again

@felixbr
Copy link
Contributor Author

felixbr commented Aug 19, 2019

Sorry, lost track of this…

No worries, I thought you were busy with your new job 😄

@travisbrown
Copy link
Contributor

Merging this now—we can look at the newtype encoding in a follow-up.

@travisbrown travisbrown merged commit c617540 into typelevel:master Aug 23, 2019
@felixbr felixbr deleted the feature/parallel-instance branch September 23, 2019 08:40
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.

3 participants