Issue
I've seen this asked a few times but I can't work out how to implement this to solve my issue.
I've basically got an array of http calls that I need to execute in sequentially order. Specifically I need to execute one, wait for it to return then execute the next.
let requests = [
this.http.post('http://localhost:4200/api/value', 'one'),
this.http.post('http://localhost:4200/api/value', 'two'),
this.http.post('http://localhost:4200/api/value', 'three'),
this.http.post('http://localhost:4200/api/value', 'four'),
];
So I'm currently using a forkJoin but this runs the requests simultaneously which is not what I want.
forkJoin(observableBatch).subscribe(result => {
// success
}, error => {
// log error
});
I read using concatMap
might be the answer but how do I use this on an array of observables?
Solution
Try with concat function of RXJS, try this
import { concat } from 'rxjs';
let requests = [
this.http.post('http://localhost:4200/api/value', 'one'),
this.http.post('http://localhost:4200/api/value', 'two'),
this.http.post('http://localhost:4200/api/value', 'three'),
this.http.post('http://localhost:4200/api/value', 'four'),
];
concat(...requests).subscribe(result => {
// success
}, error => {
// log error
});
Answered By - Ghoul Ahmed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.