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

Support Twitter futures #833

Merged
merged 22 commits into from May 9, 2019
Merged

Conversation

mijicd
Copy link
Member

@mijicd mijicd commented May 6, 2019

Closes #718.

@mijicd mijicd requested a review from jdegoes May 6, 2019 19:15
@mijicd mijicd force-pushed the twitter-futures-interop branch 2 times, most recently from 49e2221 to 3d1677f Compare May 7, 2019 11:18
Copy link
Contributor

@LGLO LGLO left a comment

Choose a reason for hiding this comment

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

Are you able to provide some simple tests? Otherwise I could add them if you are busy.

@@ -36,7 +36,7 @@ jobs:
- &scaladoc
stage: microsite
name: "Generate Scaladoc"
script: sbt ++$TRAVIS_SCALA_VERSION coreJVM/doc coreJS/doc interopCatsJVM/doc interopCatsJS/doc interopFutureJVM/doc interopFutureJS/doc interopScalaz7xJVM/doc interopScalaz7xJS/doc interopMonixJVM/doc interopMonixJS/doc interopJavaJVM/doc interopReactiveStreamsJVM/doc
script: sbt ++$TRAVIS_SCALA_VERSION coreJVM/doc coreJS/doc interopCatsJVM/doc interopCatsJS/doc interopFutureJVM/doc interopScalaz7xJVM/doc interopScalaz7xJS/doc interopMonixJVM/doc interopMonixJS/doc interopJavaJVM/doc interopReactiveStreamsJVM/doc interopTwitterJVM/doc
Copy link
Contributor

Choose a reason for hiding this comment

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

is interopFutureJS/doc gone by accident or for purpose? WHy?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was on purpose, as I think there isn't (wasn't?) such interop atm. I can reintroduce it though.

interopScalaz7xJVM,
interopScalaz7xJS,
interopJavaJVM,
interopReactiveStreamsJVM,
// benchmarks,
interopTwitterJVM,
benchmarks,
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the reason to have benchmarks commented out?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea. It was commented out for a long time now. As far as I can see it's commented out together with Monix during "death of TF" PR :).

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember it :D , I wondered why it was already commented before

@mijicd
Copy link
Member Author

mijicd commented May 7, 2019

@LGLO Thanks for the review. I will add the tests.

@mijicd mijicd requested a review from LGLO May 7, 2019 13:32
@mijicd mijicd requested a review from LGLO May 7, 2019 16:54
@mijicd
Copy link
Member Author

mijicd commented May 7, 2019

@LGLO added docs to sidebar.

package object twitter {
implicit class TaskObjOps(private val obj: Task.type) extends AnyVal {
final def fromTwitterFuture[A](future: => Future[A]): Task[A] =
Task.effectAsync { cb =>
Copy link
Member

Choose a reason for hiding this comment

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

You will also need to handle interruption from the outside with future.raise

Copy link
Member Author

@mijicd mijicd May 8, 2019

Choose a reason for hiding this comment

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

Any suggestions on the approach? From what I see, interrupt handler is available only for Promise, and raising is propagated to producers. There are facilities for making it non-interruptible, but I don't think it's the desired behavior :).

Copy link
Contributor

@yaroot yaroot May 8, 2019

Choose a reason for hiding this comment

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

I've made some change here

Interruption handler in promise is where you need to accept downstream cancellation, here you need to signal cancellation by using future.raise.

Besides that fromTwitterFuture should really accept Task[Future[A]] (similar to the scala version fromFuture).

Copy link
Member

Choose a reason for hiding this comment

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

As @yaroot did 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@yaroot fromFuture doesn't accept Task, as far as I can see, it accepts ExecutionContext => scala.concurrent.Future[A]. I'll take a look at the solution you suggested, or, I can retract the PR and let you submit the solution, if it's the preferred approach :).

Copy link
Member

Choose a reason for hiding this comment

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

@mijicd no worries, I should have been clearer 😅 Yes the Task[Future[_]] thing is rather hard to find. By name seems fine to me.

Great work 💯

Copy link
Member Author

@mijicd mijicd May 8, 2019

Choose a reason for hiding this comment

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

Thanks. I wasn't aware of this, sorry @yaroot. That being said, I see there are multiple ways we are "playing" with futures: thunks, by-name, wrapping them in IO... not sure that we need all of them.

Copy link
Contributor

@yaroot yaroot May 8, 2019

Choose a reason for hiding this comment

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

@mijicd great work. Yes they're all thunks, but IO has nice properties and easier to reason about (much easier than by-name), not to mention keeping the API in line with existing ones.

In the latest commit (https://github.com/scalaz/scalaz-zio/blob/dbc12eef5809aa34e2eae8b17e13bdcdfd7d42ed/interop-twitter/jvm/src/main/scala/scalaz/zio/interop/twitter.scala#L10-L15) the future is actually evaluated twice, if you change the variable lazy val future = ... to def future = ... or inline it like Task.fromTwitterFuture(Future.sleep(..)) the test will be broken, which would be a nightmare to debug in application code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Let's update this one to task then!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -1,3 +1,4 @@
version = "2.0.0-RC6"
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary? It's added by metals, isn't it? If possible I'd move that out of the way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, it is. All hell breaks loose if you remove it :).

Copy link
Member

Choose a reason for hiding this comment

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

Sad 😞

regiskuckaertz
regiskuckaertz previously approved these changes May 8, 2019
Copy link
Member

@regiskuckaertz regiskuckaertz left a comment

Choose a reason for hiding this comment

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

It looks good to me, thank you very much for your contribution! I've not reviewed for some time so I'll let @LGLO give a final 👍

@mijicd
Copy link
Member Author

mijicd commented May 8, 2019

@LGLO @regiskuckaertz in the end I adjusted the interface as suggested above by @yaroot. Take one more look, and hopefully the build will be green (this flaky reactive test is kinda annoying).

LGLO
LGLO previously approved these changes May 8, 2019
Copy link
Contributor

@LGLO LGLO left a comment

Choose a reason for hiding this comment

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

LGTM!

@regiskuckaertz regiskuckaertz merged commit ce37ecd into zio:master May 9, 2019
@mijicd mijicd deleted the twitter-futures-interop branch May 9, 2019 09:56
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.

Support Twitter Futures
5 participants