0
resource1$ = hash1$.map((renew: boolean) => renew ? http1$ : Observable.empty());
resource2$ = hash2$.map((renew: boolean) => renew ? http2$ : Observable.empty());
sync$ = Observable.forkJoin(resource1$, resource2$);
sync$.subscribe(() => console.log('Sync done!), (err) => console.log('Sync failed!'));
안녕하세요, 안녕하세요, 응용 프로그램을 시작할 때 API에서 동기화 할 리소스가 여러 개 있습니다. 나는 그것들을 병렬로 동기화하고 HEAD 요청을 사용하여 X-HASH 헤더를 이전에 저장된 것과 비교하는 데 필요한지 확인해야한다.조건부 RxJS 스트림
그래서 hash1 $는 HEAD 요청을 수행하고 해시를 비교하여 true 또는 false를 반환합니다.
resource1 $이 (가) Observable.empty를 반환하면 모든 $ 스트림을 취소합니다. 이유를 모르겠다.
감사합니다 마틴. 이제는 실패하지 않습니다. 그러나 .map 대신 .flatMap 연산자를 사용해야했습니다. 'hash1 $ .flatMap ((renew : boolean) => 갱신? http : // Observable.of (false));) http1 $ Observable.fromPromise입니까? – David
이것은'sync $'를 어떻게 사용 하느냐에 달려 있습니다. – martin