如果我在订阅中进行多个订阅,则第一次订阅中的complete()是否会等待?

时间:2020-08-13 06:55:01

标签: angular angular2-observables

我要在网络中初始化多个数据,所以我创建了多个订阅。

我的问题是,在没有发现错误的情况下,第一个订阅是否会等待完成所有订阅,直到它进入complete()?

这是例子

myFirstService.subscribe(
    data =>{
        mySecondService.subscribe(
            data =>{
                codes
            }
        )
    },
    error =>{},
    () => {}        <---------- will this () wait for the second service to finish?   
)

1 个答案:

答案 0 :(得分:0)

否,如果要等待第二个可观察对象完成,则需要在其中处理逻辑。

示例:

   myFirstService.subscribe(
        data =>{
            mySecondService.subscribe(
                data =>{
                    codes
                },
               () => { // do stuff after second observable finishes }
            )
        },
        error =>{},
        () => {}        <---------- this will not wait for the second observable, only for the first   
    )