【发布时间】:2020-09-30 23:51:02
【问题描述】:
我是一个新手,试图掌握 fs2 队列背后的直觉。
我正在尝试做一个从Stream[IO, Int] 提取数据的基本示例。但对我来说,文档还不够,因为它直接深入到高级内容。
这是我到目前为止所做的:
import cats.effect.{ ExitCode, IO, IOApp}
import fs2._
import fs2.concurrent.Queue
class QueueInt(q: Queue[IO, Int]) {
def startPushingtoQueue: Stream[IO, Unit] = {
Stream(1, 2, 3).covary[IO].through(q.enqueue)
q.dequeue.evalMap(n => IO.delay(println(s"Pulling element $n from Queue")))
}
}
object testingQueues extends IOApp {
override def run(args: List[String]): IO[ExitCode] = {
val stream = for {
q <- Queue.bounded(10)
b = new QueueInt(q)
_ <- b.startPushingtoQueue.drain
} yield ()
}
}
问题 1:我收到了No implicit argument of type Concurrent[F_],
知道我没有使用任何并发效果,我似乎无法弄清楚我错过了什么?
问题 2:如何打印结果。
问题 3:谁能指导我一些资源来学习 fs2
【问题讨论】: