Why awakeEvery was removed from scalaz-stream

一世执手 提交于 2019-12-24 12:44:05

问题


I found that there is no more awakeEvery inside scalaz.stream.Process in modern scalaz-stream. How to run something with period then?


回答1:


It was moved to the scalaz.stream.time package:

import scalaz.stream._

scala> implicit val sc = new java.util.concurrent.ScheduledThreadPoolExecutor(1) 
sc: java.util.concurrent.ScheduledThreadPoolExecutor = java.util.concurrent.ScheduledThreadPoolExecutor@6b9013a5[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

scala> import time._
import time._

scala> awakeEvery(1 second)
res22: scalaz.stream.Process[scalaz.concurrent.Task,scala.concurrent.duration.Duration] = Await(scalaz.concurrent.Task@798e0ec5,<function1>)

Usage:

import scalaz.stream.io._

scala> awakeEvery(1 second).map(_.toString).take(10).to(stdOutLines).run.run
1071184213 nanoseconds
2070400738 nanoseconds
3069559214 nanoseconds
4066587711 nanoseconds
5071218561 nanoseconds
6071221562 nanoseconds
7071216340 nanoseconds
8067705406 nanoseconds
9066798501 nanoseconds
10066190672 nanoseconds


来源:https://stackoverflow.com/questions/32852039/why-awakeevery-was-removed-from-scalaz-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!