Overview
Ignores source values forduration milliseconds, then emits the most recent value from the source Observable, then repeats this process.
auditTime is similar to throttleTime, but emits the last value from the silenced time window, instead of the first value.Type Signature
Parameters
Time to wait before emitting the most recent source value, measured in milliseconds or the time unit determined internally by the optional
scheduler.The SchedulerLike to use for managing the timers that handle the rate-limiting behavior.
Returns
MonoTypeOperatorFunction<T> - A function that returns an Observable that performs rate-limiting of emissions from the source Observable.
How It Works
- Initially, the internal timer is disabled
- When the first source value arrives, the timer is enabled
- After
durationmilliseconds, the timer is disabled and the most recent value is emitted - While the timer is enabled, all source values are cached (only the latest is kept)
- This process repeats for each new value
Usage Examples
Basic Example: Limit Click Rate
Track Final Scroll Position
Mouse Movement Sampling
When to Use
Use auditTime when:
- You want to rate-limit events with a fixed time window
- You need the most recent value from each time window
- Handling rapid UI events (scroll, resize, mousemove)
- Implementing “save on typing” features
- Preventing button spam
Don’t use auditTime when:
- You want the first value in each window (use
throttleTimeinstead) - You need dynamic duration based on values (use
auditinstead) - You want to wait for silence (use
debounceTimeinstead) - You need to process every value (use
bufferorbufferTime)
Common Patterns
Auto-save Draft
Throttle Analytics Events
Comparison with Similar Operators
| Operator | Emits | Duration |
|---|---|---|
auditTime | Last value in window | Fixed time |
throttleTime | First value in window | Fixed time |
audit | Last value in window | Dynamic (from Observable) |
debounceTime | Last value after silence | Fixed time |
Related Operators
- audit - Same behavior but with dynamic duration
- throttleTime - Emits the first value instead of the last
- debounceTime - Waits for silence before emitting
- sampleTime - Samples at fixed intervals
- sample - Samples when another Observable emits
