signature: delay(delay: number | Date, scheduler: Scheduler): Observable

Delay emitted values by given time.


Example 1: Delay for increasing durations

( jsBin | jsFiddle )

import { of } 'rxjs/observable/of';
import { merge } from 'rxjs/observable/merge';
import { mapTo, delay } from 'rxjs/operators';

//emit one item
const example = of(null);
//delay output of each by an extra second
const message = merge(
  example.pipe(mapTo('World!'), delay(1000)),
  example.pipe(mapTo('Goodbye'), delay(2000)),
  example.pipe(mapTo('World!'), delay(3000))
//output: 'Hello'...'World!'...'Goodbye'...'World!'
const subscribe = message.subscribe(val => console.log(val));

Additional Resources

:file_folder: Source Code:

results matching ""

    No results matching ""