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

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions streams/shared/src/main/scala/zio/stream/ZChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1012,22 +1012,21 @@ sealed trait ZChannel[-Env, -InErr, -InElem, -InDone, +OutErr, +OutElem, +OutDon
ev1: Any <:< InElem,
ev2: OutElem <:< Nothing,
trace: Trace
): ZIO[Env with Scope, OutErr, OutDone] =
ZIO
.acquireReleaseExit(
): ZIO[Env with Scope, OutErr, OutDone] = {
def run(promise: Promise[OutErr, OutDone], scope: Scope) = ZIO
.acquireReleaseExitWith(
ZIO.succeed(
new ChannelExecutor[Env, InErr, InElem, InDone, OutErr, OutElem, OutDone](
() => self,
null,
executeCloseLastSubstream = identity[URIO[Env, Any]]
)
)
) { (exec, exit) =>
) { (exec, exit: Exit[OutErr, OutDone]) =>
val finalize = exec.close(exit)
if (finalize ne null) finalize
if (finalize ne null) finalize.tapErrorCause(cause => scope.addFinalizer(ZIO.refailCause(cause)))
else ZIO.unit
}
.flatMap { exec =>
} { exec =>
ZIO.suspendSucceed {
def interpret(channelState: ChannelExecutor.ChannelState[Env, OutErr]): ZIO[Env, OutErr, OutDone] =
channelState match {
Expand All @@ -1047,9 +1046,20 @@ sealed trait ZChannel[-Env, -InErr, -InElem, -InDone, +OutErr, +OutElem, +OutDon
}

interpret(exec.run().asInstanceOf[ChannelState[Env, OutErr]])
.intoPromise(promise) *> promise.await <* ZIO.never
}
}

for {
parent <- ZIO.scope
child <- parent.fork
promise <- Promise.make[OutErr, OutDone]
fiber <- run(promise, child).forkScoped
done <- promise.await
_ <- fiber.inheritAll
} yield done
}

/**
* Run the channel until it finishes with a done value or fails with an error.
* The channel must not read any input or write any output.
Expand Down