debounceTime
signature: debounceTime(dueTime: number, scheduler: Scheduler):
Observable
Discard emitted values that take less than the specified time between
output
All your emitted items are spaced by less than 1000ms, so they are discarded.
Note : by default, the first item is not emitted directly.
If you want to get only the last operation auditTime
is the operator you are searching for.
auditTime
Ignores source values for duration
milliseconds, then emits the
most recent value from the source Observable, then repeats this
process.
function getValue() {
return rxjs.interval(100);
}
// keep the last element after 1000ms
getValue().pipe(rxjs.operators.auditTime(1000)).subscribe(data => {
console.log(data);
});
If you want to do a specific processing of all the elements received within the 1000ms, you can use bufferTime.
bufferTime
signature: bufferTime(bufferTimeSpan: number,
bufferCreationInterval: number, scheduler: Scheduler): Observable
Collect emitted values until provided time has passed, emit as array.
function getValue() {
return rxjs.interval(100);
}
getValue().pipe(
rxjs.operators.bufferTime(1000),
rxjs.operators.map(itemsList => Math.max(itemsList))
)
.subscribe(data => {
console.log(data);
});