apple / apple/swift-async-algorithms

`throttle` does not emit the latest element at interval occurrence when latest is `true`

Open
#266 33 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
3.7k
Forks
226
Avg merge
10d 3h
Merged PRs (30d)
1

Description

Unlike similar operator in `Combine` the `throttle`'s `latest` parameter is confusing, as it does not emit any latest, but a **next** element instead.

When `latest` parameter is set to `true`

#### Actual behavior:
The throttle emits the next element from the base sequence, if any, **after** the interval occurs.
Meaning if there's no new elements emitted after the interval occurrence, the latest element is just skipped, leading to only the first element being emitted.

#### Expected behavior:
The throttle emits the latest cached element **instantly** when the interval occurs.

Contributor guide

Open the contributing guide

Research direction

Start with the `throttle` operator and trace how its `latest` parameter handles the cached element when the interval occurs. Compare the behavior described here with the similar Combine operator. Done means the latest cached element is emitted immediately at the interval, including when no later base-sequence element arrives.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.