Last active
February 15, 2024 11:20
-
-
Save fancellu/7d1fa485bed3558814c660f7af84c387 to your computer and use it in GitHub Desktop.
EmberClientCall.scala (trying to work out why we get a stack trace, seems that this is a known issue)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.effect.{IO, IOApp} | |
import org.http4s.{Headers, MediaType, Method, Request} | |
import org.http4s.ember.client.EmberClientBuilder | |
import org.http4s.headers.Accept | |
import org.http4s.implicits.http4sLiteralsSyntax | |
import org.typelevel.log4cats.LoggerFactory | |
import org.typelevel.log4cats.slf4j.Slf4jFactory | |
object EmberClientCall extends IOApp.Simple { | |
private implicit val loggerFactory: LoggerFactory[IO] = | |
Slf4jFactory.create[IO] | |
private val clientResource = EmberClientBuilder | |
.default[IO] | |
.build | |
val run: IO[Unit] = { | |
for { | |
_ <- IO.println("Hello") | |
ret <- clientResource.use { | |
client => | |
client.expect[String]( | |
Request( | |
method = Method.GET, | |
uri"https://swapi.dev/api/planets/1/?format=json", | |
headers = Headers(Accept(MediaType.application.json)), | |
) | |
) | |
} | |
_ <- IO.println(s"Have run client $ret") | |
} yield () | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". | |
SLF4J: Defaulting to no-operation (NOP) logger implementation | |
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. | |
Hello | |
java.nio.channels.ClosedChannelException | |
at java.base/sun.nio.ch.AsynchronousSocketChannelImpl.begin(AsynchronousSocketChannelImpl.java:118) | |
at java.base/sun.nio.ch.AsynchronousSocketChannelImpl.shutdownInput(AsynchronousSocketChannelImpl.java:536) | |
at fs2.io.net.SocketCompanionPlatform$AsyncSocket.$anonfun$readChunk$3(SocketPlatform.scala:121) | |
at delay @ fs2.io.net.SocketCompanionPlatform$AsyncSocket.$anonfun$readChunk$2(SocketPlatform.scala:120) | |
at delay @ fs2.io.net.SocketCompanionPlatform$AsyncSocket.$anonfun$readChunk$1(SocketPlatform.scala:120) | |
at async @ fs2.io.net.SocketCompanionPlatform$AsyncSocket.readChunk(SocketPlatform.scala:114) | |
at flatMap @ fs2.io.net.SocketCompanionPlatform$BufferedReads.$anonfun$read$1(SocketPlatform.scala:82) | |
at delay @ fs2.io.net.SocketCompanionPlatform$BufferedReads.withReadBuffer(SocketPlatform.scala:52) | |
at clear @ org.http4s.client.middleware.Retry$.retryLoop$1(Retry.scala:92) | |
at getAndSet @ org.typelevel.keypool.KeyPool$.destroy(KeyPool.scala:120) | |
Have run client {"name":"Tatooine","rotation_period":"23","orbital_period":"304","diameter":"10465","climate":"arid","gravity":"1 standard","terrain":"desert","surface_water":"1","population":"200000","residents":["https://swapi.dev/api/people/1/","https://swapi.dev/api/people/2/","https://swapi.dev/api/people/4/","https://swapi.dev/api/people/6/","https://swapi.dev/api/people/7/","https://swapi.dev/api/people/8/","https://swapi.dev/api/people/9/","https://swapi.dev/api/people/11/","https://swapi.dev/api/people/43/","https://swapi.dev/api/people/62/"],"films":["https://swapi.dev/api/films/1/","https://swapi.dev/api/films/3/","https://swapi.dev/api/films/4/","https://swapi.dev/api/films/5/","https://swapi.dev/api/films/6/"],"created":"2014-12-09T13:50:49.641000Z","edited":"2014-12-20T20:58:18.411000Z","url":"https://swapi.dev/api/planets/1/"} | |
Process finished with exit code 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, known issue typelevel/fs2#3238 in v3.8.13