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

240
Views
Why are variables inside the promise undefined and not updating?

I am trying to write a package that can create some animations using setInterval. However, I need to make the animations run synchronously. Why do hor and vert become undefined and why do hiter and viter not update inside setInterval?

  animateStretchPromise(hor, vert, speed) {
    return new Promise((resolve, reject) => {
      let context = this.context;
      let cvs = this.canvas;
      let radius = this.radius
      let hiter = 1
      let viter = 1
      let cen = this.center
      let lw = this.lineWidth;
      let ac = this.arcColor;
      let hinc = (hor / 1000) * (speed / 100)
      let vinc = (vert / 1000) * (speed / 100)
      const interval = setInterval(function () {
        console.log(hiter, hor, viter, vert)
        context.beginPath()
        context.clearRect(0, 0, cvs.width, cvs.height)
        context.save();
        context.translate(cvs.width * cen.x, cvs.height * cen.y);
        context.scale(hiter, viter);
        context.translate(cvs.width * cen.x * -1, cvs.height * cen.y * -1);
        context.arc(cvs.width * cen.x, cvs.height * cen.y, radius, 0, circum, true);
        context.closePath();
        context.lineWidth = lw;
        context.strokeStyle = ac;
        context.stroke();
        context.restore();
        if (hiter >= hor && viter >= vert) {
          console.log(hiter, hor, viter, vert)
          clearInterval(interval)
          resolve("Animation Complete")
        }
        if (hiter < hor) {
          if (hiter < 1) {
            hiter -= hinc
          } else {
            hiter += hinc
          }
        } 
        if (viter < vert) {
          if (viter < 1) {
            viter -= vinc
          } else {
            viter += vinc
          }
        }
      }, 1);
    })
  }
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!