Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxScala: Simplify doOnCompleted/Terminate, finallyDo callback usage #1345

Merged
merged 1 commit into from
Jun 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -751,22 +751,31 @@ class RxScalaDemo extends JUnitSuite {
obs.toBlockingObservable.toIterable.last
}

@Test def doOnCompletedExample(): Unit = {
val o = List("red", "green", "blue").toObservable.doOnCompleted { println("onCompleted") }
o.subscribe(v => println(v), e => e.printStackTrace)
// red
// green
// blue
// onCompleted
}

@Test def doOnTerminateExample(): Unit = {
val o = List("red", "green", "blue").toObservable.doOnTerminate(() => println("terminate"))
val o = List("red", "green", "blue").toObservable.doOnTerminate { println("terminate") }
o.subscribe(v => println(v), e => e.printStackTrace, () => println("onCompleted"))
// red
// green
// blud
// blue
// terminate
// onCompleted
}

@Test def finallyDoExample(): Unit = {
val o = List("red", "green", "blue").toObservable.finallyDo(() => println("finally"))
val o = List("red", "green", "blue").toObservable.finallyDo { println("finally") }
o.subscribe(v => println(v), e => e.printStackTrace, () => println("onCompleted"))
// red
// green
// blud
// blue
// onCompleted
// finally
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ trait Observable[+T]
* an function to be invoked when the source Observable finishes
* @return an Observable that emits the same items as the source Observable, then invokes the function
*/
def finallyDo(action: () => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.finallyDo(action))
def finallyDo(action: => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.finallyDo(() => action))
}

/**
Expand Down Expand Up @@ -3406,8 +3406,8 @@ trait Observable[+T]
* `onCompleted`
* @return the source Observable with the side-effecting behavior applied
*/
def doOnCompleted(onCompleted: () => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.doOnCompleted(onCompleted))
def doOnCompleted(onCompleted: => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.doOnCompleted(() => onCompleted))
}

/**
Expand Down Expand Up @@ -3461,8 +3461,8 @@ trait Observable[+T]
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-doonterminate">RxJava Wiki: doOnTerminate()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229804.aspx">MSDN: Observable.Do</a>
*/
def doOnTerminate(onTerminate: () => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.doOnTerminate(onTerminate))
def doOnTerminate(onTerminate: => Unit): Observable[T] = {
toScalaObservable[T](asJavaObservable.doOnTerminate(() => onTerminate))
}

/**
Expand Down