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

192
Views
Is there a way to make async function sync?

I have code like this.

async function doAsync(count){
  //external function I need to use
  count++;
  console.log("async count is "+ count );
  return await count;
}
 
function makeSyncChain(i){
  //my chain that I could change
  i=doAsync(i);
  return i;
}

let val=0;
console.log("sync count is " + makeSyncChain(val));
so like at the example, I have sync chain and one of the chain function is async, is there a way to make async function working in sync chain?

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

0

Correct solution must be:

async function doAsync(count){
  //external function I need to use
  count++;
  console.log("async count is "+ count );
  return await count;
}

let val=0;
console.log("sync count is " + (await doAsync(val)));

But in wrong key may be written as (and yes it won't work, it will just hang the browser):

async function doAsync(count){
  //external function I need to use
  count++;
  console.log("async count is "+ count );
  return await count;
}
 
function makeSyncChain(i){
  //my chain that I could change
  let isDone = false;
  let result;
  doAsync(i).then(r => {
    result = r;
  }).finally(() => {
    isDone = true;
  });
  while (!isDone);
  return result;
}

let val=0;
console.log("sync count is " + makeSyncChain(val));

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!