All Downloads are FREE. Search and download functionalities are using the official Maven repository.

spice.http.client.HttpClientImplementation.scala Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package spice.http.client

import cats.effect.IO
import cats.implicits.toTraverseOps
import scala.concurrent.duration.FiniteDuration

trait HttpClientImplementation {
  private var instances = Map.empty[String, HttpClientInstance]

  def connectionPool(maxIdleConnections: Int, keepAlive: FiniteDuration): ConnectionPool

  final def instance(client: HttpClient): HttpClientInstance = synchronized {
    instances.get(client.instanceKey) match {
      case Some(i) => i
      case None =>
        val i = createInstance(client)
        instances += client.instanceKey -> i
        i
    }
  }

  protected def createInstance(client: HttpClient): HttpClientInstance

  def dispose(): IO[Unit] = instances.map(_._2.dispose()).toList.sequence.map { _ =>
    instances = Map.empty
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy