1

I have a function which returns an array of Observables

function getMultipleObservables() {
    let coordinationObservables: Observable<any>[] = [];
    coordinationObservables.push(Observable.of([1,2,3,4]))
    coordinationObservables.push(Observable.of([1,2,3,4]))
    return coordinationObservables
}

I have another part of code chains multiple observables like this:

this.someService.flatMap(()=>{
    return Observable.forkJoin((getMultipleObservables())=>{
        //handle the responses
    })
}).subscribe(()=>{

})

So my question is how could I properly pass a function as a parameter to the forkJoin, and handle it in the callback function.

1 Answer 1

2

Use the spread operator.

return Observable.forkJoin(...getMultipleObservables()).map((data) => {
     // do something, write your code here
     // later subscribe it wherever it is returning
     // using map() like this is works for rxjs < 5.5,
     // use it under pipe() if you have a higher version
     // like: forkjoin(...getMultipleObservables()).pipe(map());
     return modifiedData // if modified, else no need to add map
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.