swift-async-algorithms: A throttled `AsyncSequence` doesn't yield its parent sequence's final value

Not sure if this is expected behavior.

I make an AsyncStream called stream, and a throttled sequence from that stream throttledStream. I yield values into stream for a while, and eventually call finish() on its continuation. All the while in the background I am iterating through throttledStream - when finish() gets called on stream, my iteration through throttledStream finishes, but I don’t get the final value that was sent to stream.

Sorry this is kind of a complicated way to explain the issue, but I will make a reproducible example project if this behavior sounds like it is indeed not intended!

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 24 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Combine for example used the rule for throttle and debounce: that the iterative output (not the signals to determine failure or finishedness) are the rate limited things. So specifically for throttle; it means that even the last value should not emit any faster than the requested throttling rate.

The intent for folks using throttle is that they don’t ever want a rate beyond a given value. Making the last value ignore that would break folks expectations.

We can definitely have a latest: true option here. The implementation should also be quite trivial, if we get nil from the upstream and we have a last value and latest = true then we can do a Task.sleep until the timeout has passed.

I’m fairly certain the current debounce implementation will not emit the final value in all cases.

If that happens and you can reproduce it please open a separate issue here.