Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit Dns for IO only #475

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "3.2"
ThisBuild / tlBaseVersion := "3.3"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-breaking. FS2 will be affected, at least.


ThisBuild / organization := "com.comcast"
ThisBuild / organizationName := "Comcast Cable Communications Management, LLC"
Expand Down Expand Up @@ -46,7 +46,6 @@ lazy val testKit = crossProject(JVMPlatform, JSPlatform, NativePlatform)
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % "1.17.0",
"org.scalameta" %%% "munit-scalacheck" % "1.0.0-M7" % Test,
"org.typelevel" %%% "cats-effect" % "3.4.8" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3" % Test
)
)
Expand Down Expand Up @@ -78,7 +77,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
libraryDependencies ++= Seq(
"org.typelevel" %%% "literally" % "1.1.0",
"org.typelevel" %%% "cats-core" % "2.9.0",
"org.typelevel" %%% "cats-effect-kernel" % "3.4.8",
"org.typelevel" %%% "cats-effect" % "3.4.8",
Comment on lines -81 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now depend on Cats Effect core :)

"org.scalacheck" %%% "scalacheck" % "1.17.0" % Test
)
)
Expand Down
2 changes: 1 addition & 1 deletion js/src/main/scala/com/comcast/ip4s/DnsPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import scala.scalajs.js.|
import scala.scalajs.js.annotation.JSImport

private[ip4s] trait DnsCompanionPlatform {
implicit def forAsync[F[_]](implicit F: Async[F]): Dns[F] = new UnsealedDns[F] {
def forAsync[F[_]](implicit F: Async[F]): Dns[F] = new UnsealedDns[F] {
def resolve(hostname: Hostname): F[IpAddress] =
F.fromPromise(F.delay(dnsPromises.lookup(hostname.toString, LookupOptions(all = false))))
.flatMap { address =>
Expand Down
5 changes: 4 additions & 1 deletion jvm-native/src/main/scala/com/comcast/ip4s/DnsPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@

package com.comcast.ip4s

import cats.effect.kernel.Async
import cats.effect.kernel.Sync
import cats.syntax.all._

import java.net.InetAddress

private[ip4s] trait DnsCompanionPlatform {
implicit def forSync[F[_]](implicit F: Sync[F]): Dns[F] = new UnsealedDns[F] {
def forAsync[F[_]: Async]: Dns[F] = forSync // alias for cross-compiling w/ JS

def forSync[F[_]](implicit F: Sync[F]): Dns[F] = new UnsealedDns[F] {
Comment on lines -25 to +28
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just make these def impl or something.

def resolve(hostname: Hostname): F[IpAddress] =
F.blocking {
val addr = InetAddress.getByName(hostname.toString)
Expand Down
4 changes: 4 additions & 0 deletions shared/src/main/scala/com/comcast/ip4s/Dns.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.comcast.ip4s

import cats.effect.IO

/** Capability for an effect `F[_]` which can do DNS lookups.
*
* An instance is available for any effect which has a `Sync` instance on JVM and `Async` on Node.js.
Expand Down Expand Up @@ -66,4 +68,6 @@ private[ip4s] trait UnsealedDns[F[_]] extends Dns[F]

object Dns extends DnsCompanionPlatform {
def apply[F[_]](implicit F: Dns[F]): F.type = F

implicit def forIO: Dns[IO] = forAsync[IO]
}