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

331
Visualizações
waiting for an api call back to finish before calling another api in vuex

I have this action in vuex which basically calls two APIs. modifyResults has a call back function and I want to wait for this callback to finish then execute the updateResults. This is my setup:

//vuex

import {modifyResults, updateResults} from './api';
const actions = {
  async modifyResults({ dispatch }) {
    try {
      // waiting for ModifyResults to finish entirely but after
      // functionOne from api folder is finished
      // it executes updateResults from here and then executes
      // functionTwo from api folder
      await modifyResults();
      dispatch('updateResults');
    } catch (error) {
      // catch errors
    } finally {
      // loading variable set to false
    }
  },
  async updateResults({ dispatch }, ) {
    try {
      const { sources } = await updateResults();
      dispatch('setItems', sources);
    } 
    //blah blah
  },
}

// api.js

export const modifyResults = async () => {
  await functionOne({someApi},
    async functionTwo(status, resposne) => {
      const { data } = await api.post(//blah blah);
      return data
    }
  )
},
export const updateResults = async () => {
  // blah return result
},

So basically what happens is this is the order in which these functions are executed:

1- functionOne
2- updateResults
3- functionTwo

whereas I want this order:

1- functionOne
2- functionTwo
3- updateResults
about 4 years ago · Juan Pablo Isaza
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