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