角2诺言/可观测链的两个事件? [英] Angular 2 promise/observable chain two events?
本文介绍了角2诺言/可观测链的两个事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想知道的观察到或诺可在下列情况下使用中使用角2:
I'm wondering if observable or promise can be used in the following use case in angular 2:
有两个异步上传任务。我想知道我怎么可以检测任务就完成了。
There are two asynchronized upload tasks. I'd like to know how I can detect both tasks are finished.
我的上传任务(在诺,但它很容易被更改为实施观察到如果需要的话)是这样的:
My upload task (implemented in promise but it's easily be changed to observable if needed) is like this:
myService.upload('upload1').then(() => {
})
myService.upload('upload2').then(() => {
})
如何将这两个事件一起链在任何的诺或可观测让我知道,这两个任务完成?谢谢
How to chain these two events together in either promise or observable so that I know both tasks are finished? Thanks
推荐答案
完整
当所有的源流关闭被执行。
complete
is executed when all the source stream are closed.
Rx.Observable.merge(
myService.upload('upload1'),
myService.upload('upload2').subscribe({complete: () => { ... });
如果你想设置结果的最大数量,以等待
if you want to set a max number of results to wait for
Rx.Observable.merge(
myService.upload('upload1'),
myService.upload('upload2')
.take(2)
.subscribe({complete: () => { ... });
这篇关于角2诺言/可观测链的两个事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文