반응형
RxJS: shareReplay에서 bufferSize란?
무슨 말인지 모르겠다.bufferSize
매개 변수 평균 및 그 영향은 무엇인가?
다음의 차이점은 무엇인가?
var published = source
.shareReplay();
var published = source
.shareReplay(0)
var published = source
.shareReplay(1);
var published = source
.shareReplay(10);
버퍼 크기:
- BufferSize는 캐시되고 재생된 항목의 수를 의미한다.
- 가입 시 특정 배출량을 재생한다.
- 구독자가 없는 경우에도 캐시된 항목 유지
문제 제기:
var published = source
.shareReplay();
이것에 대한 어떤 가입자도 소스에 의해 방출되는 모든 항목/데이터 스트림을 얻을 것이다.
var published = source
.shareReplay(0)
마지막으로 내보낸 값을 캐시할 것이다.
var published = source
.shareReplay(1);
위와 같이 마지막 방출 값을 캐싱할 것이다.
var published = source
.shareReplay(10);
출처가 배출한 마지막 10개 품목을 캐시한다.
자세한 정보 : 이 개념을 한 가지 예를 들어 설명하겠다.
let source$ = interval(1000)
.pipe(
take(5),
shareReplay(3)
)
source$.subscribe(res => console.log('1st time=>', res))
setTimeout(() => {
source$.subscribe(res => console.log('2nd time=>', res))
}, 5000)
참고: 여기 첫 번째 가입은 단지 가치 발산을 시작하려는 것을 의미한다.Take 연산자를 사용하여 배출 간격을 제한하면서 5회 값을 방출한다. 출력한다.
1st time=> 0
1st time=> 1
1st time=> 2
1st time=> 3
1st time=> 4
이제 두 번째 관측 가능한 값에 집중하십시오. bufferSize 값이 3으로 설정되어 있으므로 마지막 세 개의 방출된 값을 기록할 수 있음
2nd time=> 2
2nd time=> 3
2nd time=> 4
source --1--2--3--4--5--6--7
subscriber -----------S---------
와 함께source.shareReplay(2)
subscriber
을 얻을 것이다[2, 3, 4, 5,...]
참조URL: https://stackoverflow.com/questions/34922079/rxjs-what-is-buffersize-in-sharereplay
반응형
'IT이야기' 카테고리의 다른 글
python에서 받아쓰기의 깊은 사본 (0) | 2022.03.23 |
---|---|
슬롯에서 카테고리 값을 가져오는 방법(일정관리 설정) (0) | 2022.03.23 |
TypeScript 파일이 변경될 때 ts-node를 감시하고 다시 로드하는 방법 (0) | 2022.03.23 |
python에서 float를 정수로 변환하는 가장 안전한 방법? (0) | 2022.03.23 |
[False, True]에서 "not(참)"이 False를 반환하는 이유는? (0) | 2022.03.23 |