Skip to content

Instantly share code, notes, and snippets.

@bearprada
Created January 2, 2019 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearprada/c2ae51b66f6a55beeb0c9aba8f3ba3ed to your computer and use it in GitHub Desktop.
Save bearprada/c2ae51b66f6a55beeb0c9aba8f3ba3ed to your computer and use it in GitHub Desktop.
Test Delay with FlatMap operator
fun `test delay`() {
Observable.just(listOf(1,2,3,4,5))
.flatMap { nums ->
val obs = mutableListOf<Observable<Int>>()
for (i in nums) {
obs.add(Observable.just(i).delay(i.toLong(), TimeUnit.MILLISECONDS))
}
Observable.merge(obs)
}
.subscribe { println("$it") }
Thread.sleep(6000)
}
@bearprada
Copy link
Author

Expected log message should be

1
2
3
4
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment