Skip to content

Commit e455d19

Browse files
zsxwingjbripley
authored andcommitted
Update the signature of "schedule" methods
1 parent 5e2fb32 commit e455d19

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -805,22 +805,20 @@ class RxScalaDemo extends JUnitSuite {
805805
@Test def schedulerExample2(): Unit = {
806806
val latch = new CountDownLatch(1)
807807
val worker = IOScheduler().createWorker
808-
worker.schedule(
809-
{
810-
println("Hello from Scheduler after 1 second")
811-
latch.countDown()
812-
}, 1 seconds)
808+
worker.schedule(1 seconds) {
809+
println("Hello from Scheduler after 1 second")
810+
latch.countDown()
811+
}
813812
latch.await(5, TimeUnit.SECONDS)
814813
}
815814

816815
@Test def schedulerExample3(): Unit = {
817816
val worker = IOScheduler().createWorker
818817
var no = 1
819-
val subscription = worker.schedulePeriodically(
820-
{
821-
println(s"Hello(${no}) from Scheduler")
822-
no += 1
823-
}, initialDelay = 1 seconds, period = 100 millis)
818+
val subscription = worker.schedulePeriodically(initialDelay = 1 seconds, period = 100 millis) {
819+
println(s"Hello(${no}) from Scheduler")
820+
no += 1
821+
}
824822
TimeUnit.SECONDS.sleep(2)
825823
subscription.unsubscribe()
826824
}
@@ -831,9 +829,9 @@ class RxScalaDemo extends JUnitSuite {
831829
def hello: Unit = {
832830
println(s"Hello(${no}) from Scheduler")
833831
no += 1
834-
worker.schedule(hello, 100 millis)
832+
worker.schedule(100 millis)(hello)
835833
}
836-
val subscription = worker.schedule(hello, 1 seconds)
834+
val subscription = worker.schedule(1 seconds)(hello)
837835
TimeUnit.SECONDS.sleep(2)
838836
subscription.unsubscribe()
839837
}

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/Scheduler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ trait Worker extends Subscription {
6969
* @param delay time to wait before executing the action
7070
* @return a subscription to be able to unsubscribe the action (unschedule it if not executed)
7171
*/
72-
def schedule(action: => Unit, delay: Duration): Subscription = {
72+
def schedule(delay: Duration)(action: => Unit): Subscription = {
7373
this.asJavaWorker.schedule(
7474
new Action0 {
7575
override def call(): Unit = action
@@ -102,7 +102,7 @@ trait Worker extends Subscription {
102102
* @param period the time interval to wait each time in between executing the action
103103
* @return a subscription to be able to unsubscribe the action (unschedule it if not executed)
104104
*/
105-
def schedulePeriodically(action: => Unit, initialDelay: Duration, period: Duration): Subscription = {
105+
def schedulePeriodically(initialDelay: Duration, period: Duration)(action: => Unit): Subscription = {
106106
this.asJavaWorker.schedulePeriodically(
107107
new Action0 {
108108
override def call(): Unit = action

0 commit comments

Comments
 (0)