可观察到的forkJoin不触发

编程入门 行业动态 更新时间:2024-10-22 08:39:11
本文介绍了可观察到的forkJoin不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在两个Observables上使用用户forkJoin.其中之一以流的形式开始...如果我直接订阅它们,则会收到响应,但forkJoin不会触发.有任何想法吗?

I'm trying to user forkJoin on two Observables. One of them starts as a stream... If I subscribe to them directly I get a response, forkJoin isn't firing though. Any ideas?

private data$: Observable<any[]>; private statuses$: Observable<any[]>; private queryStream = new Subject<string>(); .... this.data$ = this.queryStream .startWith('') .flatMap(queryInput => { this.query = queryInput return this._companyService.getCompanies(this.queryRequired + ' ' + this.query, this.page, this.sort); }) .share(); ... Observable.forkJoin(this.statuses$, thispanies$) .subscribe(res => { console.log('forkjoin'); this._countStatus(res[0], res[1]); }); // This shows arrays in the console... this.statuses$.subscribe(res => console.log(res)); thispanies$.subscribe(res => console.log(res)); // In the console Array[9] Array[6]

推荐答案

forkJoin的一个非常普遍的问题是,它要求所有源Observable都发出至少一项,并且所有它们都必须完成.

A very common problem with forkJoin is that it requires all source Observables to emit at least one item and all of them have to complete.

换句话说,如果this.statuses$或thispanies$不发出任何项目,并且直到它们都完成forkJoin时才发出任何东西.

In other words if this.statuses$ or thispanies$ doesn't emit any item and until they both complete the forkJoin won't emit anything.

this.statuses$.subscribe( res => console.log(res), undefined, () => console.log('completed'), );

更多推荐

可观察到的forkJoin不触发

本文发布于:2023-10-27 18:48:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534231.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:观察到   forkJoin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!