1 year ago

#108357

test-img

yonatan omer

Preventing Cats.IO to be executed in parallel

Forcing Cats.IO to be evaluated on a dedicated thread pool

How can I prevent the line.split to be executed on the Blocker[IO] execution context? I hoped the IO effect will be evaluated on Two dedicated threads obtained from parEvalMapUnordered. Should I shift context somehow?

    Blocker[IO].use { blocker => {
          val processorPipe: Pipe[IO, Byte, Byte] =
            src =>
              src.through(text.utf8Decode)
                .through(text.lines)
                .parEvalMapUnordered(2)(line => {
                  IO.eval(Eval.now {
                    println("Thread: " + Thread.currentThread().getId)
                    line.split("\\W+")
                  })
                })

Output shows many threads:

Thread: 32
Thread: 32
...
Thread: 38
Thread: 38
...
Thread: 40
...
Thread: 41

multithreading

scala

cats-effect

fs2

0 Answers

Your Answer

Accepted video resources