juan_gandhi: (VP)
[personal profile] juan_gandhi
Here's the essence of cache as I wrote about earlier tonight.

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") }
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 18th, 2025 08:23 am
Powered by Dreamwidth Studios
OSZAR »