8000 Allow application to exit on normal completion by kyri-petrou · Pull Request #8811 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow application to exit on normal completion #8811

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 3 commits into from
May 2, 2024
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
18 changes: 9 additions & 9 deletions core/jvm/src/main/scala/zio/ZIOAppPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ private[zio] trait ZIOAppPlatformSpecific { self: ZIOApp =>
runtime.unsafe.run {
ZIO.uninterruptibleMask { restore =>
for {
fiberId <- ZIO.fiberId
p <- Promise.make[Nothing, Set[FiberId.Runtime]]
interrupt = interruptRootFibers(p)
fiber <- restore(workflow)
.foldCauseZIO(
cause => interrupt *> exit(ExitCode.failure) *> ZIO.refailCause(cause),
_ => interrupt *> exit(ExitCode.success)
)
.fork
fiberId <- ZIO.fiberId
p <- Promise.make[Nothing, Set[FiberId.Runtime]]
fiber <- restore(workflow).onExit { exit0 =>
val exitCode = if (exit0.isSuccess) ExitCode.success else ExitCode.failure
val interrupt = interruptRootFibers(p)
// If we're shutting down due to an external signal, the shutdown hook will fulfill the promise
// Otherwise it means we're shutting down due to normal completion and we need to fulfill the promise
ZIO.unless(shuttingDown.get())(p.succeed(Set(fiberId))) *> interrupt *> exit(exitCode)
}.fork
_ <-
ZIO.succeed(Platform.addShutdownHook { () =>
if (!shuttingDown.getAndSet(true)) {
Expand Down
0