Questions tagged [cats-effect]

Part of the Scala Cats ecosystem for an IO type and associated effects.

191 questions
3
votes
1 answer

How to terminate FS2 stream started from SBT Shell?

If I run this program from SBT shell, then cancel it, it will keep printing "hello". I have to exit SBT to make it stop. Why is that? import cats.effect.{ExitCode, IO, IOApp} import fs2.Stream import scala.concurrent.duration._ object FS2 extends…
Cpt. Senkfuss
  • 1,347
  • 3
  • 12
  • 20
3
votes
2 answers

How to asynchronously interrupt an fs2 stream?

I'm trying to interrupt an fs2 stream with SignalRef. I set up and run the stream with the following. The stream should run when switch contains false and should interrupt when switch contains true import cats.effect.IO import fs2.Stream …
mdornfe1
  • 1,982
  • 1
  • 24
  • 42
3
votes
2 answers

How to configure Cats Timer on abstract effect type

Let's say I have a following method signature in a project using Cats-effect and tagless final approach: def schedule[F[_]: Applicative : Async: Timer] I'm trying to schedule an operation on a schedule method call using pure FP. I tried this…
3
votes
1 answer

How to read from embedded-kafka with fs2-kafka

I am using fs2-kafka to read from embedded-kafka. I create the embedded kafka using withRunningKafkaOnFoundPort, create topic and publish a few messages. However when I try to read it back with fs2-kafka I get a NullPointerException. I have isolated…
Lev Denisov
  • 2,011
  • 16
  • 26
3
votes
1 answer

Cannot find an implicit value for ContextShift

I am trying to create webapp with http4s that is based on Http4sServlet. The following code does not compile: import cats.effect._ import org.http4s.servlet.BlockingServletIo import org.http4s.servlet.Http4sServlet import…
softshipper
  • 32,463
  • 51
  • 192
  • 400
3
votes
1 answer

fs2.Stream[IO, Something] does not return on take(1)

I have a function that returns a fs2.Stream of Measurements. import cats.effect._ import fs2._ def apply(sds: SerialPort, interval: Int)(implicit cs: ContextShift[IO]): Stream[IO, SdsMeasurement] = for { blocker <-…
Jeroen Kransen
  • 1,379
  • 3
  • 19
  • 45
3
votes
1 answer

http4s Received premature EOF

I want to implement an http4s server that receives the content from another service, processes it and return the response. The original service uses redirects so I added the Follow redirect middleware. I also added the Logger middleware to check…
Labra
  • 1,412
  • 1
  • 13
  • 33
3
votes
1 answer

Integration tests for Http4s Client/Resource

I'm implementing a Vault client in Scala using Http4s client. And I'm now starting to write integration tests. So far I have this: abstract class Utils extends AsyncWordSpec with Matchers { implicit override def executionContext =…
Simão Martins
  • 1,210
  • 11
  • 22
3
votes
2 answers

Resolve Seq[Future[Either[A, Seq[B]]]] - Scala Cats

I am facing an issue while I am trying to resolve the result of a method. More specifically I have: def methodA(): Future[Either[Error, Seq[A]]] and at some point, I want to call this method for each element of a list and merge the result.…
pik4
  • 1,283
  • 3
  • 21
  • 56
3
votes
2 answers

Stream URL to a local file with fs2

Using fs2 (ver. 1.0.4) and cats-effect IO, I can stream an URL to a local file, import concurrent.ExecutionContext.Implicits.global def download(spec: String, filename: String): Stream[IO, Unit] = io.readInputStream((new…
thlim
  • 2,908
  • 3
  • 34
  • 57
3
votes
1 answer

cats-effect: How to obtain an implicit NonEmptyParallel

I am trying to use parMapN function and I am not able to compile the code. If my type is IO then there is not problem, but when I use types on my functions, then I cannot manage to make it work. In the snippet below, there is randomMessage which…
3
votes
1 answer

what is the equivalent of fs2.Scheduler in fs2 (0.10.x) in newer versions

I'm migrating fs2 0.10.x version to version 1.0.0. Our code uses fs2.Scheduler in from fs2 version 0.10.x. I don't know what is the equivalent in newer fs2 version 1.0.0. I went through the migration guide here but couldn't find the migration…
user51
  • 8,843
  • 21
  • 79
  • 158
2
votes
1 answer

How to shutdown Cats Effect Runtime

Is there a way to shutdown the cats effect runtime from within an application, similar to System.exit(0)? There is a shutdown method on IORuntime but it is not documented and it behaves weirdly when I call it on IORuntime.global: it does not shut…
2
votes
0 answers

Programmatically configuring logback-classic in a Typelevel Scala application

I have a program using com.monovore.decline and org.typelevel.log4cats. app.scala //> using scala 3 //> using resourceDir ./resources //> using dep org.typelevel::log4cats-slf4j:2.6.0 //> using dep ch.qos.logback:logback-classic:1.4.8 //> using dep…
2
votes
1 answer

Cats Effect IO - how do I ensure thrown exceptions are captured as values when using attempt / redeem "inside" a top level flatmap?

I am attempting to pass some data (an event) through a program composed out of smaller IOs. I need to run a computation (which can throw an exception) based on the event, then report out on what happened including the original event in the…