In the following code:
async createPanoramas ({ dispatch, commit, rootState }, newPanoramas = {}) {
const { enterprise = '' } = rootState.route.query
const splitNewPanoramas = []
const clonedNewPanoramas = newPanoramas.panoramas.slice()
while (clonedNewPanoramas.length) {
splitNewPanoramas.push(clonedNewPanoramas.splice(0, MAX_ARRAY_EACH_API_CALL))
}
return splitNewPanoramas.forEach(async panoramasPayload => {
const payload = {
buildingId: newPanoramas.buildingId,
panoramas: panoramasPayload
}
const urlEnd = '/v2/panoramas'
const type = 'post'
const resp = await api.asyncRequest(urlEnd, type, payload).catch(resp => {
console.log('Before response')
return resp
})
}
// payload = [{"objectId":"2cd2244c-31bf-424b-831e-35360f422363","index":1},{"objectId":"012fd0f8-1bc9-4336-81fc-afd46836b0c9","index":2}]
this.createPanoramas(payload).then(resp => {
console.log('After then')
})
The console log 'Before resp'
will trigger after 'After then'
.
Why is this? And how to modify the async function so 'Before resp'
triggers BEFORE 'After then'
?