dealing with time
Apr. 7th, 2016 11:43 amHere's the essence of cache as I wrote about earlier tonight.
Note that you can override
trait TimeReader {
def currentTime: Long = System.currentTimeMillis
def flowOfTime = Iterator.iterate(currentTime){_ => currentTime}
def interval(n:Long) = {
flowOfTime.next // the first drop, may be stale
val end = flowOfTime.next + n
flowOfTime takeWhile (end >)
}
def interval(duration: Duration) = interval(duration.toMillis)
//...
Note that you can override
currentTime
for {
value <- readFromSource
t <- interval(60 seconds)
} useThisValue(value)
e.g.
for {i <- 1 to 10; t <- interval(1 second) } {Thread.sleep(1); println(s"$i @$t") }