skip to content

debounceTime

 

debounceTime operator will emit a value from the source stream only if a given time has passed without source producing more values.

Also try this debounceTime vs throttleTime vs auditTime vs sampleTime head-to-head comparison

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const { rxObserver, palette } = require('api/v0.3');
const { merge, timer, from } = require('rxjs');
const { map, zip, debounceTime, takeUntil } = require('rxjs/operators');

// stream for coloring
const palette$ = from(palette);

const source$ = merge(
    timer(0, 330),
    timer(50, 180)
  ).pipe(
    // colorize each item
    zip(palette$, Marble),
    map(setCurrentTime),
    takeUntil(timer(1000))
  );

source$
  .subscribe(rxObserver());

source$.pipe(
    debounceTime(100),
    map(setCurrentTime)
  )
  .subscribe(rxObserver('debounceTime(100)'));


// helpers
// keeps colors, updated value to Date.now
function setCurrentTime({ color }){
  return Marble(Date.now(), color);
}

// creates a colored Marble
function Marble(value, color) {
  return {
    valueOf: ()=>value
    , color
  };
}

⚠️ Execution time is limited to 1000ms
0msstartcomplete00 5050 230230 330330 410410 590590 660660 770770 950950 990990 debounceTime(100)startcomplete150150 510510 760760 870870 10001000