L
L
Leopandro2018-03-05 21:47:21
Angular
Leopandro, 2018-03-05 21:47:21

How to resolve the end of execution of several asynchronous functions?

There are several functions:

this.userService.getLegalsList(this.getUserListParams()).subscribe(data => {
//лишний код
}
this.userService.getAll({params : {all:true,blocked:'0',role:'driver'}}).subscribe(data => {
//лишний код
}
route.data.subscribe(data => { 
//лишний код
}

The task is simple - you need to somehow detect the completion of all these functions and then execute another function. Moreover, it is not cool to perform consistently - the site is too slow.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kn1ght_t, 2018-03-05
@kn1ght_t

Promise.all

A
Advarius, 2018-08-16
@Advarius

const legalUsers$ = this.userService.getLegalsList(...);
const allUsers$ = this.userService.getAll(...);
const routeData$ = route.data;

legalUser$
    .combineLatest(allUser$, routeData$)
    .subscribe(([data1, data2, data3]) => {
        ...
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question