问题
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