Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda