Created
November 9, 2016 08:19
-
-
Save cvoronin/8f54d503c4b94a4ea49cca10392a9778 to your computer and use it in GitHub Desktop.
Emit items with delay: 1 ... delay ... 2 ... delay ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun testEmitWithDelays() { | |
val DELAY = 500L | |
val COUNT = 5 | |
val latch = CountDownLatch(1) | |
val startMoment = System.currentTimeMillis() | |
var endMoment : Long = 0 | |
Observable | |
.range(0, COUNT) | |
.flatMap( { Observable.just(it).delay(DELAY, TimeUnit.MILLISECONDS) }, 1) // maxConcurrent = 1 | |
.subscribe( | |
{ println("... value: $it, ${System.currentTimeMillis() - startMoment}") }, | |
{}, | |
{ | |
endMoment = System.currentTimeMillis() | |
latch.countDown() | |
}) | |
latch.await() | |
assertTrue { endMoment - startMoment >= DELAY * COUNT } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment