Predict the output
Values arrive at 0 ms, 100 ms, 200 ms and 800 ms. With .debounce(for: .milliseconds(300), ...), what is emitted?
// input: a@0ms b@100ms c@200ms d@800ms
subject
.debounce(for: .milliseconds(300), scheduler: RunLoop.main)
.sink { print($0) }Hint 1 of 1
Look for gaps longer than 300 ms.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: B c at about 500 ms, then d at about 1100 ms
Correct. Each burst emits its last value 300 ms after the burst ends.
Why not the others?
- A a, b, c, d. Debounce drops values that are followed quickly by another.
- C a at 0 ms, then d at 800 ms. That is closer to throttle with latest: false.
- D Only d. c is followed by 600 ms of quiet, which is longer than 300 ms.