.debounce() not working as expected

While using .debounce() with networking call it is swallowing the values it receives. With the combine() usage, it is emitting events as expected, but they carry no data. Below is the example code.

Code Block
URLSession.shared.dataTaskPublisher(for: request)
      .map(\.data)
      .decode(type: AddressList.self, decoder: JSONDecoder())
      .debounce(for: 0.3, scheduler: DispatchQueue.main)

Accepted Answer
Using debounce on a single-element publisher like dataTaskPublisher does not make sense.
What sort of output do you expect with using debounce?
I am trying to debounce the API call when a user enters something in TextField.

I am trying to debounce the API call when a user enters something in TextField.

Not clear enough, but I guess you should better make the TextField change as a publisher and apply debounce on it.
As described in the documentation

This operator is useful to process bursty or high-volume event streams where you need to reduce the number of values delivered to the downstream to a rate you specify.

dataTaskPublisher emits only one event, not bursty nor high-volume event streams.


Thanks! Using debounce on TextField change works.
.debounce() not working as expected
 
 
Q