Skip to content

Commit 79ce193

Browse files
start TestScheduler
1 parent af7d056 commit 79ce193

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package rx.lang.scala.concurrency
2+
3+
import scala.concurrent.duration.Duration
4+
import rx.lang.scala.Subscription
5+
import rx.lang.scala.Scheduler
6+
import rx.lang.scala.ImplicitFunctionConversions._
7+
import rx.util.functions.Func2
8+
import java.util.concurrent.TimeUnit
9+
10+
// TODO make a Scheduler interface in Java, and a DefaultScheduler Java and one for Scala
11+
12+
class TestScheduler extends Scheduler {
13+
14+
private val asJava = new rx.concurrency.TestScheduler
15+
16+
override def now: Long = asJava.now
17+
18+
def advanceTimeBy(time: Duration) {
19+
asJava.advanceTimeBy(time.length, time.unit)
20+
}
21+
22+
def advanceTimeTo(time: Duration) {
23+
asJava.advanceTimeTo(time.length, time.unit)
24+
}
25+
26+
def triggerActions() {
27+
asJava.triggerActions()
28+
}
29+
30+
def schedule[T](state: T, action: (Scheduler, T) => Subscription): Subscription = {
31+
asJava.schedule(state, action)
32+
}
33+
34+
def schedule[T](state: T, action: (Scheduler, T) => Subscription, delay: Duration): Subscription = {
35+
asJava.schedule(state, action, delay.length, delay.unit)
36+
}
37+
38+
override def schedule[T](state: T, action: Func2[_ >: Scheduler, _ >: T, _ <: Subscription]): Subscription = {
39+
asJava.schedule(state, action)
40+
}
41+
42+
override def schedule[T](state: T, action: Func2[_ >: Scheduler, _ >: T, _ <: Subscription], delayTime: Long, unit: TimeUnit): Subscription = {
43+
asJava.schedule(state, action, delayTime, unit)
44+
}
45+
46+
}

0 commit comments

Comments
 (0)