skip to content

delayWhen

 

delayWhen delays value emission by another stream. In this example we'll delay source stream emissions by their numeric values:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const { rxObserver } = require('api/v0.3');
const { from, timer } = require('rxjs');
const { delayWhen } = require('rxjs/operators');

const source$ =  from([ 0, 15, 20, 25, 5, 10 ]);

const delayed$ = source$.pipe(
    delayWhen(x => timer(x))
  );
  
source$.subscribe(rxObserver('source$'));
delayed$.subscribe(rxObserver('delayed$'));

0mssource$startcomplete00 1515 2020 2525 55 1010 delayed$startcomplete00 55 1010 1515 2020 2525

To delay values emission by constant time — see delay operator example