File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
language-adaptors/rxjava-scala/src
examples/scala/rx/lang/scala/examples Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -799,4 +799,12 @@ class RxScalaDemo extends JUnitSuite {
799
799
assertFalse(o1.sequenceEqual(o3).toBlockingObservable.single)
800
800
assertTrue(o1.sequenceEqual(o4).toBlockingObservable.single)
801
801
}
802
+
803
+ @ Test def takeExample (): Unit = {
804
+ val o = (1 to 20 ).toObservable
805
+ .zip(Observable .interval(300 millis))
806
+ .map(_._1)
807
+ .take(2 seconds)
808
+ println(o.toBlockingObservable.toList)
809
+ }
802
810
}
Original file line number Diff line number Diff line change @@ -1457,6 +1457,33 @@ trait Observable[+T]
1457
1457
toScalaObservable[T ](asJavaObservable.take(n))
1458
1458
}
1459
1459
1460
+ /**
1461
+ * Returns an Observable that emits those items emitted by source Observable before a specified time runs out.
1462
+ * <p>
1463
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/take.t.png">
1464
+ *
1465
+ * @param time the length of the time window
1466
+ * @return an Observable that emits those items emitted by the source Observable before the time runs out
1467
+ */
1468
+ def take (time : Duration ): Observable [T ] = {
1469
+ toScalaObservable[T ](asJavaObservable.take(time.length, time.unit))
1470
+ }
1471
+
1472
+ /**
1473
+ * Returns an Observable that emits those items emitted by source Observable before a specified time (on
1474
+ * specified Scheduler) runs out
1475
+ * <p>
1476
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/take.ts.png">
1477
+ *
1478
+ * @param time the length of the time window
1479
+ * @param scheduler the Scheduler used for time source
1480
+ * @return an Observable that emits those items emitted by the source Observable before the time runs out,
1481
+ * according to the specified Scheduler
1482
+ */
1483
+ def take (time : Duration , scheduler : Scheduler ) {
1484
+ toScalaObservable[T ](asJavaObservable.take(time.length, time.unit, scheduler.asJavaScheduler))
1485
+ }
1486
+
1460
1487
/**
1461
1488
* Returns an Observable that emits items emitted by the source Observable so long as a
1462
1489
* specified condition is true.
You can’t perform that action at this time.
0 commit comments