-
Couldn't load subscription status.
- Fork 1.4k
Support a custom executor in StreamEffect #1483
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
Conversation
bf46926 to
72543f8
Compare
|
Ah, this forgets the executor between the combinators. Fixing this now. |
|
For interruption, we'll need to support different interruption strategies that propagate on the |
edd9d04 to
e480dea
Compare
|
|
||
| private[stream] class StreamEffect[-R, +E, +A]( | ||
| val processEffect: ZManaged[R, E, () => A], | ||
| val executor: ZIO[R, Nothing, Executor] |
There was a problem hiding this comment.
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
reserveof the managed - Invocation of "close" occurs on the blocking thread pool, which we can do in the
reserveof managed (on finalization) - Invocation of the "pull" occurs on the blocking thread pool, which we can also do (below, using
effectBlockinginstead ofeffectTotal, etc.).
So unless I'm missing something, we can do this w/o new machinery. Right? Or wrong? 😄
There was a problem hiding this comment.
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
xand starts pulling it. ThePullonxevaluates the() => Athunk while locked to the Blocking executor (StreamEffect.scala:34), so that pull runs on the blocking executor; - opens
yand starts pulling it. Similarly, it evaluates the thunk while locked to the default executor, so that pull runs there. - opens
zand starts pulling it. ThatPulldoes 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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.
56dded1 to
e8e347d
Compare
7f8f54a to
77619a5
Compare
77619a5 to
b8e1072
Compare
|
@iravid What is the status of this one? |
|
I'll circle back to this soon. Let's close it out for now. |
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