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

123
Views
why loop works sync in Promise

my problem is why loop in side of the promise works like sync code for example


console.log('im working')
function proLoop(){
    return new Promise((resolve ,rejects)=>{
        for (let i = 0; i < 1000000000000; i++) {}
        console.log('loop is done')
    })
}

proLoop();

console.log('im working')


So even if we write is like promise it will get more time and freezes our code In other words it will works synchronically so why its happening and how to solve it ?

Update

i find a solution but why it works?

so the solution is just warp your code as like resolved promise

like this

    return Promise.resolve().then( ()=>{
        for (let i = 0; i < 1000000000000; i++) {}
        console.log('loop is done')
    })

but why???

about 4 years ago · Juan Pablo Isaza
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!