I have googled and googled and can't seem to get out of this wet paper bag I find myself in.
I have an exported function that grabs a bunch of data from a web api, then we do some stuff to that data, go back and grab a little more data, and then finally return a javascript object back. At least that's the plan. I have everything working right up to the point where I have to send the data back from the module into my main app.js file.
Here is what I hope to be the relevant code from my function...there is lots I omitted, but I don't think it's relevant.
//SNIP
let airportBoards = [...results];
const updateBoards = () => {
airportBoards.forEach(airport => {
console.log(airport)
boardTypes.forEach(board => {
let currentOffset = airport[board].next_offset;
(async function () {
while (currentOffset > 0) {
await getOffsetData(airport.airport, board, currentOffset) //axios request
.then(res => {
currentOffset = res.data.AirportBoardsResult[board].next_offset
newFlights = res.data.AirportBoardsResult[board].flights
console.log(currentOffset)
let index = airportBoards.findIndex(r => r.airport === airport.airport)
airportBoards[index][board].flights.push(...newFlights)
})
}
})()
})
})
}
Ultimately what I need to do is get the contents of the "airportBoards" back out of this. Everything is working as far as I can tell, it loops through the offsets, and calls until there is no more data to return. And I can see the airportBoards array is updating properly using the debugging tools...I just can't figure out how to use it (airportBoards) once all the async/await stuff is settled.
Apologies in advance...I know its not pretty...I just hope I have provided enough information here for someone to give me a hand.
Thanks in advance!