juan_gandhi: (VP)
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") }
juan_gandhi: (VP)
trait TimeReader {
  def currentTime: Long = System.currentTimeMillis
}


...
class DataSomething(val name:String, val number:Long...) extends TimeReader {...}


...
val sut = new DataSomething("Ivanov", 42,...) with MockTime

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

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 18th, 2025 11:56 pm
Powered by Dreamwidth Studios
OSZAR »