Omar Mainegra
04/30/2020, 4:31 PMdebounce
in iOS, for some reason is NOT waiting the timeout
@Test
fun `'debounce' using Main scheduler works`() {
val timeout = 10L
val time = getTimeMillis()
val wasCalled = AtomicBoolean(false)
observableOf(1, 2, 3, 4, 5)
.debounce(timeout, mainScheduler)
.subscribe { value ->
val elapsed = getTimeMillis() - time
assertTrue("Should have passed more than $timeout millis, but was $elapsed") { elapsed >= timeout }
assertEquals(5, value)
wasCalled.value = true
}
await(2*timeout.toInt())
assertTrue("`subscribe` was not called") { wasCalled.value }
}
The test fails
kotlin.AssertionError: Should have passed more than 10 millis, but was 1
ioScheduler
and computationScheduler
,delay
is used instead of debounce
it works as well.
PS: The await
functions just runs the current Loop:
private fun await(millis: Int) {
NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeInterval(millis.toDouble()/1000.0, NSDate.now))
}
Arkadii Ivanov
04/30/2020, 4:44 PM5
almost immediately after subsription. The output looks correct.Omar Mainegra
04/30/2020, 4:46 PMArkadii Ivanov
04/30/2020, 4:46 PMOmar Mainegra
04/30/2020, 4:47 PMArkadii Ivanov
04/30/2020, 4:47 PMOmar Mainegra
04/30/2020, 4:47 PMtimeout
as wellArkadii Ivanov
04/30/2020, 4:48 PMOmar Mainegra
04/30/2020, 4:49 PMArkadii Ivanov
04/30/2020, 4:50 PMOmar Mainegra
04/30/2020, 4:52 PMArkadii Ivanov
04/30/2020, 4:52 PMOmar Mainegra
04/30/2020, 4:53 PMArkadii Ivanov
04/30/2020, 4:53 PMOmar Mainegra
04/30/2020, 4:53 PMArkadii Ivanov
04/30/2020, 4:54 PMobservable<Int> { (1..5).forEach(it::onNext) }
Omar Mainegra
04/30/2020, 4:56 PMArkadii Ivanov
04/30/2020, 5:00 PM