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

169
Views
How to make JavaScript asynchronous so that I can accept user input?

When the webpage loads I am running this code:

for(let i = 0; i < count;) {
    
    ...
    
    if(condition) {
        //draw with canvas api
        ++i
    }
}

It's a potentially infinite while/for loop that draws some art.

If I keep the art variables reasonable, then the piece finishes and the loop exists. But sometimes it could take several minutes or potentially run forever.

The problem is, when this is happening the browser can't accept any user input. So, there's no way for the user to halt the algorithm, eg. with a button.

How can I receive user input while running this loop?

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!