skip to content

startWith

 

Prepend a stream with a value. This value will be synchronously emitted upon subscription:

NOTE: also take a look at rxjs/defaultIfEmpty/ to handle EMPTY Observables.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const { rxObserver } = require('api/v0.3');
const { interval } = require('rxjs');
const { startWith, take } = require('rxjs/operators');

interval(10)
  .pipe(
    take(5)
  )
  .subscribe(rxObserver('interval(10)'));

interval(10)
  .pipe(
    startWith('🐶'),
    take(5)
  )
  .subscribe(rxObserver('startWith(🐶)'));
0msinterval(10)startcomplete00 11 22 33 44 startWith(🐶)startcomplete🐶🐶 00 11 22 33