RxJS how do I make POST requests in sequence where a new request is fired only when the previous completed?

Noob

Here is a simplified scenario:

   of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
  .pipe(
    map((data) => {
      let arr: Observable<any>[] = [];

      for (let elem of data) {
        let obj = {
          title: 'foo' + 'elem',
          body: 'bar' + 'elem',
          userId: elem,
        };

        arr.push(
          this.http.post(
            `https://jsonplaceholder.typicode.com/posts`,
            obj,
            {
              headers: {
                'Content-type': 'application/json; charset=UTF-8',
              },
            }
          )
        );
      }

      return arr;
    }),
    concatMap((data) => forkJoin([...data])),
  )
  .subscribe((data) => console.log(data));

My understanding is that in this case all requests are going to be fired in parallel because that's what forkJoin([...data]) does. I'm trying to figure out how I can fire a request only if the previous one completed (succeeded or failed, doesn't matter).

I'd appreciate any suggestions or help. Thanks.

Andrei

just use concat instead of forkJoin

concatMap((data) => concat(data)),

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I detect requests initiated by the new fetch standard? How should I detect an AJAX request in general?

How to fire a new http request only when the first one is completed and ignore/cancel all the other requests in between

how to cancel a previous requests when new request come from the same user in the same session

How to make a post request with the Python requests library?

How do I allow post requests from my pages only?

How do I make sure a HTTP request is only called once?

ajax looping settimeout, new request only after previous request is completed

How to make a sequence of http requests in Angular 6 using RxJS

How do I append new line break and retain the previous line break after an event is fired?

When are my post requests being fired based on woocomerce events, and how do I console my php code so I can debug

Using rxjs how can I queue HTTP requests such that it waits for an existing request to complete and then sends only the most recent request?

How do I call a function when I make a post request at Python?

How to wait until the previous post request is completed in JavaScript+Node.js?

How do I use RxJS & Observables to do an http request only after multiple other events have fired?

How Do I Make a POST Request with Node.JS to Ghostbin?

How to get an object from Firebase only when the previous object is completed?

What can I do to execute multiple Singles but only moving to the next when the previous is completed?

How do I make a HTTP HEAD request using requests?

How do I use Python requests to mimc a POST request I make in curl?

How do send my JWT token when I make a GET/POST request to the api endpoint through UI?

Using python requests to post - How do I get the correct table data I request?

How make request to MirajeJS js only when I need it

Nodejs, How do I wait until the previous post request is completed

How many http requests do I make, when I request the document page with Requests in Python 3.9?

How do I make it where you can only be between ages 15 and 80 when inputting date of birth

How do I make a POST request using axios in react?

How do I use RxJS to post transactions such that the next request waits for the previous one complete?

Preventing Multiple Requests in React until Previous Request is Completed

When I request a python requests post, I'm wondering what PHP needs to do to get it