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

203
Views
How do I go back to the beginning of the function in asynchronous structure?

I don't know if the problem is asynchronous but my code didn't work here How do I get it to recheck every second on the else side if the if function in dat().then is false? Currently my dat() function in settimeout is not working. I didn't expect it to work anyway

var dat = async () => {
        await document.querySelector("body").click();
}

dat().then(() => {
    if(document.querySelector("body").className.indexOf("position") == -1){
       console.log("right");
    }
    else setTimeout(arguments.callee, 1000);

})
dat();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Here's my attempt to write your code with the looping the stated desired loop.

var dat = async () => {
    await document.querySelector("body").click();
}

const unclicked = () => (
    document.querySelector("body").className.indexOf("position") == -1);

do {
    await dat();
    if (unclicked())
        console.log("right");
    else
        setTimeout(arguments.callee, 1000);
} while (true) 

However, I admit I agree with Kevin B's comment in that setTimeout and `document.querySelector(...).click() don't return Promises.

If you care to comment, I will gladly update the answer to reflect the question.

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!