Skip to content

Commit

Permalink
Use Mutex instead of Semaphore(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge authored Apr 22, 2023
1 parent 9dd4f57 commit af791d6
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package skunk.net.protocol

import cats.syntax.all._
import cats.effect.implicits._
import cats.effect.std.Semaphore
import cats.effect.std.Mutex
import cats.effect.Concurrent

trait Exchange[F[_]] {
Expand All @@ -15,10 +15,10 @@ trait Exchange[F[_]] {

object Exchange {
def apply[F[_]: Concurrent]: F[Exchange[F]] =
Semaphore[F](1).map { sem =>
Mutex[F].map { mut =>
new Exchange[F] {
override def apply[A](fa: F[A]): F[A] =
sem.permit.use(_ => fa).uncancelable
mut.lock.surround(fa).uncancelable
}
}
}

0 comments on commit af791d6

Please sign in to comment.