8000 Inherit child fibers created by merged streams by kyri-petrou · Pull Request #9180 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Inherit child fibers created by merged streams #9180

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

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading 8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion streams-tests/shared/src/test/scala/zio/stream/ZStreamSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,26 @@ object ZStreamSpec extends ZIOBaseSpec {
s3 = s1.zipLatest(s2).interruptWhen(ZIO.never).take(3)
_ <- s3.runDrain
} yield assertCompletes
} @@ exceptJS(nonFlaky)
} @@ exceptJS(nonFlaky),
test("i9091 - forked children are not interrupted early by interruptWhen") {
for {
requestQueue <- Queue.unbounded[String]
counter <- Ref.make(0)
_ <- ZStream
.unwrapScoped(
ZStream
.fromQueue(requestQueue)
.runForeach(_ => counter.update(_ + 1))
.fork
.as(ZStream.succeed("") ++ ZStream.never)
)
.interruptWhen(ZIO.never)
.runDrain
.fork
_ <- requestQueue.offer("some message").forever.fork
_ <- counter.get.repeatUntil(_ >= 10)
} yield assertCompletes
} @@ exceptJS(nonFlaky) @@ TestAspect.timeout(10.seconds)
),
suite("interruptAfter")(
test("interrupts after given duration") {
Expand Down
17 changes: 15 additions & 2 deletions streams/shared/src/main/scala/zio/stream/ZChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zio.{ZIO, _}
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.stream.internal.{AsyncInputConsumer, AsyncInputProducer, ChannelExecutor, SingleProducerAsyncInput}
import ChannelExecutor.ChannelState
import zio.internal.FiberScope

/**
* A `ZChannel[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone]` is a nexus
Expand Down Expand Up @@ -968,8 +969,20 @@ sealed trait ZChannel[-Env, -InErr, -InElem, -InDone, +OutErr, +OutElem, +OutDon
}
}

ZChannel
.fromZIO(pullL.forkIn(scope).zipWith(pullR.forkIn(scope))(BothRunning(_, _, true): MergeState))
def inheritChildren(parentScope: FiberScope): UIO[Unit] =
ZIO.withFiberRuntime[Any, Nothing, Unit] { (state, _) =>
state.transferChildren(parentScope)
Exit.unit
}

ZChannel.fromZIO {
ZIO.withFiberRuntime[Env1, Nothing, MergeState] { (parent, _) =>
val inherit = inheritChildren(parent.scope)
val fL = pullL.ensuring(inherit).forkIn(scope)
val fR = pullR.ensuring(inherit).forkIn(scope)
fL.zipWith(fR)(BothRunning(_, _, true))
}
}
.flatMap(go)
.embedInput(input)
}
Expand Down
Loading
0