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

Skip to content

Conversation

@iravid
Copy link
Member

@iravid iravid commented Aug 25, 2019

This is needed to support running the thunk on the blocking executor in fromInputStream.

@jdegoes - wdyt? It's a bit patchy, but I'm not sure if we need anything more than this for now.

cc @vasilmkd

@iravid iravid requested a review from jdegoes August 25, 2019 19:50
@iravid iravid force-pushed the streameffect-executor branch from bf46926 to 72543f8 Compare August 25, 2019 19:53
@iravid
Copy link
Member Author

iravid commented Aug 25, 2019

Ah, this forgets the executor between the combinators. Fixing this now.

@iravid
Copy link
Member Author

iravid commented Aug 25, 2019

For interruption, we'll need to support different interruption strategies that propagate on the StreamEffect between the combinators. E.g. fromInputStream wants Thread.interrupt, filter wants Fiber.unsafeIsInterrupted, and fromInputStream(...).filter(...) wants both.

@iravid iravid force-pushed the streameffect-executor branch 2 times, most recently from edd9d04 to e480dea Compare August 26, 2019 07:06

private[stream] class StreamEffect[-R, +E, +A](
val processEffect: ZManaged[R, E, () => A],
val executor: ZIO[R, Nothing, Executor]
Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell, this structure doesn't compose with well-defined semantics. Consider, e.g. x ++ y — what is the executor for such a composite?

It seems like we need to say three things:

  • Invocation of "open" occurs on the blocking thread pool, which we can do in the reserve of the managed
  • Invocation of "close" occurs on the blocking thread pool, which we can do in the reserve of managed (on finalization)
  • Invocation of the "pull" occurs on the blocking thread pool, which we can also do (below, using effectBlocking instead of effectTotal, etc.).

So unless I'm missing something, we can do this w/o new machinery. Right? Or wrong? 😄

Copy link
Member Author

@iravid iravid Aug 26, 2019

Choose a reason for hiding this comment

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

Say x: StreamEffect uses a Blocking executor, y: StreamEffect uses a regular executor, and z: Stream that is asynchronous.

(x ++ y ++ z).process does the following:

  • opens x and starts pulling it. The Pull on x evaluates the () => A thunk while locked to the Blocking executor (StreamEffect.scala:34), so that pull runs on the blocking executor;
  • opens y and starts pulling it. Similarly, it evaluates the thunk while locked to the default executor, so that pull runs there.
  • opens z and starts pulling it. That Pull does whatever it wants because it's effectful.

From how I'm reading things, the semantics here are identical to the semantics of lock, as long as we always propagate the executor when composing StreamEffect values. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

@jdegoes

Sorry, I realized I didn't respond to your questions about whether it's possible to do this without new machinery.

The problem is as follows: how does a constructor (like fromInputStream), which only produces a thunk Managed[E, () => A], indicate that when a stream which is based on it is run, it should be run on the Blocking threadpool? We can't use effectBlocking because we want to produce synchronous code that runs in the thunk.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jdegoes Any thoughts on the above? :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

I was busy with the huge ZSink rewrite PR, where are we with this?

@iravid @jdegoes

Copy link
Member Author

Choose a reason for hiding this comment

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

We hashed it over deadlift sets. I believe @jdegoes is onboard. I'll pick this back up next week :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome. Please keep me in the review loop.

@iravid iravid force-pushed the streameffect-executor branch 2 times, most recently from 56dded1 to e8e347d Compare September 24, 2019 04:11
@iravid iravid force-pushed the streameffect-executor branch 2 times, most recently from 7f8f54a to 77619a5 Compare October 6, 2019 19:53
@iravid iravid force-pushed the streameffect-executor branch from 77619a5 to b8e1072 Compare October 6, 2019 19:59
@jdegoes
Copy link
Member

jdegoes commented Oct 28, 2019

@iravid What is the status of this one?

@iravid
Copy link
Member Author

iravid commented Oct 28, 2019

I'll circle back to this soon. Let's close it out for now.

@iravid iravid closed this Oct 28, 2019
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