Skip to content

Commit

Permalink
Simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvgica committed Nov 25, 2021
1 parent ab58b1c commit d3ca69c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions managerial/src/main/scala/ca/dvgi/managerial/Managed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,19 @@ trait Managed[+T] { selfT =>
def build() = new Resource[U] {
private val t = selfT.build()

private var toThrow: Throwable = null

private val u =
try {
f(t.get).build()
} catch {
case throwable: Throwable =>
toThrow = throwable

case setupThrowable: Throwable =>
try {
t.teardown()
} catch {
case throwable: Throwable =>
toThrow.addSuppressed(throwable)
case teardownThrowable: Throwable =>
setupThrowable.addSuppressed(teardownThrowable)
}

throw toThrow
throw setupThrowable
}

def get = u.get
Expand Down

0 comments on commit d3ca69c

Please sign in to comment.