skip to content

take

 

take(N) will take maximum N values from the source stream and will complete after that

Also check out this first vs take vs single head-to-head comparison

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

const source$ = timer(0, 100);

const result$ = source$.pipe(
    take(5)
  );

source$.subscribe(rxObserver('source'));
result$.subscribe(rxObserver('take(5)'));
⚠️ Execution time is limited to 1000ms
0mssourcestart00 11 22 33 44 55 66 77 88 99 1010 take(5)startcomplete00 11 22 33 44

There are also takeUntil and takeWhile operators