@@ -21,15 +21,15 @@ import scala.concurrent.duration.Duration
21
21
import scala .concurrent .duration .DurationInt
22
22
import scala .concurrent .duration .DurationLong
23
23
import scala .language .postfixOps
24
+ import scala .language .implicitConversions
24
25
25
26
import org .junit .Assert .assertEquals
26
27
import org .junit .Assert .assertTrue
27
28
import org .junit .Ignore
28
29
import org .junit .Test
29
30
import org .scalatest .junit .JUnitSuite
30
31
31
- import rx .lang .scala .Notification
32
- import rx .lang .scala .Observable
32
+ import rx .lang .scala ._
33
33
import rx .lang .scala .concurrency ._
34
34
35
35
@ Ignore // Since this doesn't do automatic testing, don't increase build time unnecessarily
@@ -132,15 +132,14 @@ class RxScalaDemo extends JUnitSuite {
132
132
}
133
133
134
134
@ Test def rangeAndBufferExample () {
135
- val o = Observable (1 to 18 )
135
+ val o = Observable .from (1 to 18 )
136
136
o.buffer(5 ).subscribe((l : Seq [Int ]) => println(l.mkString(" [" , " , " , " ]" )))
137
137
}
138
138
139
139
@ Test def windowExample () {
140
- // this will be nicer once we have zipWithIndex
141
- (for ((o, i) <- Observable (1 to 18 ).window(5 ) zip Observable (0 until 4 ); n <- o)
142
- yield s " Observable# $i emits $n" )
143
- .subscribe(output(_))
140
+ (for ((o, i) <- Observable .from(1 to 18 ).window(5 ).zipWithIndex; n <- o)
141
+ yield s " Observable# $i emits $n"
142
+ ).subscribe(output(_))
144
143
}
145
144
146
145
@ Test def testReduce () {
@@ -217,6 +216,7 @@ class RxScalaDemo extends JUnitSuite {
217
216
}).flatten.toBlockingObservable.foreach(println(_))
218
217
}
219
218
219
+ @ Ignore // TODO something's bad here
220
220
@ Test def timingTest1 () {
221
221
val numbersByModulo3 = Observable .interval(1000 millis).take(9 ).groupBy(_ % 3 )
222
222
@@ -368,13 +368,13 @@ class RxScalaDemo extends JUnitSuite {
368
368
369
369
@ Test def parallelExample () {
370
370
val t0 = System .currentTimeMillis()
371
- Observable (1 to 10 ).parallel(work(_)).toBlockingObservable.foreach(println(_))
371
+ Observable .from (1 to 10 ).parallel(work(_)).toBlockingObservable.foreach(println(_))
372
372
println(s " Work took ${System .currentTimeMillis()- t0} ms " )
373
373
}
374
374
375
375
@ Test def exampleWithoutParallel () {
376
376
val t0 = System .currentTimeMillis()
377
- work(Observable (1 to 10 )).toBlockingObservable.foreach(println(_))
377
+ work(Observable .from (1 to 10 )).toBlockingObservable.foreach(println(_))
378
378
println(s " Work took ${System .currentTimeMillis()- t0} ms " )
379
379
}
380
380
@@ -402,11 +402,10 @@ class RxScalaDemo extends JUnitSuite {
402
402
}
403
403
404
404
val o1 = Observable .interval(100 millis).take(3 )
405
- val o2 = Observable (new IOException (" Oops" ))
405
+ val o2 = Observable .error (new IOException (" Oops" ))
406
406
printObservable(o1)
407
- // waitFor(o1)
408
407
printObservable(o2)
409
- // waitFor(o2 )
408
+ Thread .sleep( 500 )
410
409
}
411
410
412
411
@ Test def materializeExample2 () {
@@ -431,6 +430,17 @@ class RxScalaDemo extends JUnitSuite {
431
430
val condition = true
432
431
Observable (" a" , " b" ).zipWithIndex.takeWhile{case (elem, index) => condition}.map(_._1)
433
432
}
433
+
434
+ @ Test def createExample () {
435
+ val o = Observable .create[String ](observer => {
436
+ // this is bad because you cannot unsubscribe!
437
+ observer.onNext(" a" )
438
+ observer.onNext(" b" )
439
+ observer.onCompleted()
440
+ Subscription {}
441
+ })
442
+ o.subscribe(println(_))
443
+ }
434
444
435
445
def output (s : String ): Unit = println(s)
436
446
0 commit comments