rxjs
Version:
Reactive Extensions for modern JavaScript
20 lines • 651 B
JavaScript
import { EMPTY } from '../observable/empty';
import { operate } from '../util/lift';
import { OperatorSubscriber } from './OperatorSubscriber';
export function take(count) {
return count <= 0
?
() => EMPTY
: operate((source, subscriber) => {
let seen = 0;
source.subscribe(new OperatorSubscriber(subscriber, (value) => {
if (++seen <= count) {
subscriber.next(value);
if (count <= seen) {
subscriber.complete();
}
}
}));
});
}
//# sourceMappingURL=take.js.map