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
Add Stream#flatMapPar, Stream.flatten and Stream.mergeAll #840
Conversation
efe7af8
to
86dcb49
Compare
) | ||
} yield () | ||
) | ||
.onInterrupt(ZIO.children.flatMap(Fiber.interruptAll) *> out.shutdown) |
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.
Isn't this redundant with the line below?
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.
supervise
is the one that adds a supervisor that interrupts all children; supervised
just enables supervision so children are tracked and introspectable by ZIO.children
:-)
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.
😰 ah yeah, I remember. I have some catching up to do!
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 probably need better names too... like enableSupervision
and cleanupChildren
or something...
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.
yeah. I am constantly confused between the two ;-)
Deferring the outer stream's completion to after the inner fibers complete actually seems quite difficult with the current encoding of For example, say we have the following stream: Stream
.bracket(acquire)(release) { resource =>
resource.read
}
.mapM { element =>
process(element).fork
}
.foldLeft(List[Fiber[Nothing, Element]]())((fibers, fiber) => fiber :: fibers)
.flatMap(Fiber.joinAll) By the time If anyone has a clever idea, I'd love to hear it! |
I tried some approaches of encoding a "finalization" step into the stream's fold; e.g. something like Another thought I had: if |
@iravid All right, I began reviewing this today. At a high level, the strategy for Can you explain this:
Specifically, it's clear this is the case because the data passes through a queue, which will be out-of-sync with the input stream; buffered by some number of elements. But since the child fibers only read from the queue, it should not be an issue; and if it is, we can always avoid exiting the Or is there another more fundamental problem that I'm not seeing? |
Yeah that’s the fundamental issue. The problem is that I could not find a way to delay the outer stream from completing until the child fibers are empty. When folding, there’s no way to know that you’re at the last element and join the remaining fibers :-/ |
Going to revisit these combinators after restructuring |
Resolves #836.
I'm going to add a bunch of more tests that exercise errors, interruption and other issues, but I'd love to get comments on the implementation and possible simplifications.
Pending fixes:
Take.Fail
, which would cause the output stream to fail; however nothing in this case would stop the driver streamStream.bracket
would release its resources before the inner fibers complete