如何解决CombineLatest不能与诺言一起使用
我想执行一些顺序的代码,但是我无法从CombineLatest中提取数据
const { datosPersona,participante } = await combineLatest(
this.store.select('datosPersona'),this.store.select('participante')
).pipe(
map((data) => ({ datosPersona: data[0],participante: data[1] }),).toPromise();
解决方法
使用.toPromise()
时,流必须结束才能将其转换为Promise,然后应用程序才能继续。如果可观察到的是寿命长的一个(就像您拥有的那样),它将永远无法解决。
尝试使用take
运算符完成流。
import { take } from 'rxjs/operators';
.....
const { datosPersona,participante } = await combineLatest(
this.store.select('datosPersona'),this.store.select('participante')
).pipe(
map((data) => ({ datosPersona: data[0],participante: data[1] }),take(1),// take the first emission and only the first one
).toPromise(); // now it can be converted to a promise since the stream finished
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。