Skip to content

Commit

Permalink
Scope lock acquisition more tightly
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge authored Sep 21, 2023
1 parent bc3bb0c commit 2b1f537
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions std/shared/src/main/scala/cats/effect/std/Hotswap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ object Hotswap {
def initialize: F[Ref[F, State]] =
F.ref(Cleared)

def finalize(state: Ref[F, State]): F[Unit] = exclusive.surround {
def finalize(state: Ref[F, State]): F[Unit] =
state.getAndSet(Finalized).flatMap {
case Acquired(_, finalizer) => finalizer
case Acquired(_, finalizer) => exclusive.surround(finalizer)
case Cleared => F.unit
case Finalized => raise("Hotswap already finalized")
}
}

def raise(message: String): F[Unit] =
F.raiseError[Unit](new RuntimeException(message))
Expand Down

0 comments on commit 2b1f537

Please sign in to comment.