Skip to content

Instantly share code, notes, and snippets.

@rossabaker
Last active April 10, 2020 00:29
Show Gist options
  • Save rossabaker/feed1f51f4da5b88280eb49c1320ad00 to your computer and use it in GitHub Desktop.
Save rossabaker/feed1f51f4da5b88280eb49c1320ad00 to your computer and use it in GitHub Desktop.
import cats.effect._
import cats.effect.concurrent._
import org.http4s._
import org.http4s.client._
object Benash {
def permitResource[F[_]](sem: Semaphore[F])(implicit F: Bracket[F, Throwable]): Resource[F, Unit] =
Resource.make(sem.acquire)(_ => sem.release)
def limitedClient(sem: Semaphore[IO], client: Client[IO]): Client[IO] =
Client { req: Request[IO] =>
permitResource(sem).flatMap { _ => client.run(req) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment