Fix streaming subscription bug. (#2983)

This commit is contained in:
josecoll 2018-04-20 11:07:36 +01:00 committed by GitHub
parent ca55c80bfc
commit 1c7def8e12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -5,6 +5,7 @@ import net.corda.behave.file.currentDirectory
import net.corda.behave.logging.getLogger
import net.corda.behave.process.output.OutputListener
import rx.Observable
import rx.Subscriber
import java.io.Closeable
import java.io.File
import java.io.IOException
@ -143,8 +144,9 @@ open class Command(
return exitCode
}
fun use(action: (Command, Observable<String>) -> Unit = { _, _ -> }): Int {
fun use(subscriber: Subscriber<String>, action: (Command, Observable<String>) -> Unit = { _, _ -> }): Int {
try {
output.subscribe(subscriber)
start()
action(this, output)
} finally {

View File

@ -21,8 +21,7 @@ class CommandTests {
@Test
fun `output stream for command can be observed`() {
val subscriber = TestSubscriber<String>()
val exitCode = Command(listOf("ls", "/")).use { _, output ->
output.subscribe(subscriber)
val exitCode = Command(listOf("ls", "/")).use(subscriber) { _, output ->
subscriber.awaitTerminalEvent()
subscriber.assertCompleted()
subscriber.assertNoErrors()