Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to call sequentially axios functions without callback

I need to make function syncCalltest which call axios functions sequentially.
Is there any way to make syncCallTest function run sequentially without modifying getPost1 getPost2 and getPost3??

function syncCallTest() {
    conole.log('before getPost');
    getPost();
    conole.log('after getPost and before getPost2');
    getPost2();
    conole.log('after getPost2 and before getPost3');
    getPost3();
    conole.log('after getPost3');
}

function getPost() {
  axios get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}

function getPost2() {
  axios get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}

function getPost3() {
  axios get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since your calls are Promise, I dont think you can make then synchronous.

But it seems that what you need is to have the call sequentially, then this is easy ;)

Change the postX methods so that they return their promise and then cascade the promises

function syncCallTest() {
  getPost()
    .then(getPost2)
    .then(getPost3);
}

function getPost() {
  return axios.get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}

function getPost2() {
  return axios.get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}

function getPost3() {
  return axios.get("http://example.com/posts/12345/")
    .then(reponse => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    })
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!