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

154
Views
How can I change setTimeout to send the request until a value is received?

In my app I've got functionality where user can import spreadsheet file. The file itself is sending to backend app and after some time it the result can be fetched from different endpoint based on ID. The thing is it can take a very long time for the backend to prepare a response and this time varies depending on the file size. So far I've been using setTimeout function but since the backend response time is different I can't do it.

Here is my code:

new_batch.vue

export default {
  name: 'BackboneSyncProducts',
  data() {
    return {
      styleCodes: [],
      fetchedProductSyncResult: [],
      loadId: null,
    }
  },
  watch: {
    loadId(newValue, oldValue) {
      if (!oldValue && newValue) {
        setTimeout(() => {
          fetchSyncedProductsResultRequest(this, newValue).then(response => {
            this.fetchedProductSyncResult = response.data['result']
          })
        }, 3000)
      }
    }
  },

Whole functionality needs to be asynchronous. How to hit backend app using fetchSyncedProductsResultRequest function until response.data['result'] is not is null ?

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

0

Try sending several requests using setInterval until the file will be processed on backend and will return a non-null value. You can also use websockets but that will require updating backend API.

export default {
  name: 'BackboneSyncProducts',
  data() {
    return {
      styleCodes: [],
      fetchedProductSyncResult: [],
      loadId: null,
    }
  },
  watch: {
    loadId(newValue, oldValue) {
      if (!oldValue && newValue) {
        const intervalId = setInterval(() => {
          fetchSyncedProductsResultRequest(this, newValue).then(response => {
            if (response.data['request']) {
              clearInterval(intervalId);
              this.fetchedProductSyncResult = response.data['result']
            }
          })
        }, 1000)
      }
    }
  },
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!