async function not returning value

I am trying to return buildings and access it in the promise at the bottom of the script, but it seems like the console.log in the then part of the promise is executing before the getRecord function finishes, and so I can’t access the array I am creating.

async function getRecords() {
     const buildings =[]
     data =updateTable.select({
        fields:['building_name']
    }).eachPage(function page(records, fetchNextPage){
        
        records.forEach(function(record){
            num++
            //console.log(num)
            try{
             //console.log(record['fields']['building_name'])
             
             buildings.push(record['fields']['building_name'])
            }
            catch(err){
                console.log('hello1')
                console.log(err)
            }

        }) 
            try{
        fetchNextPage()
            }
            
            catch{
                console.log('hello2')
                return buildings;
            }
    },function (err) {
        console.log(err)
        console.log('hello3')
        if (err) {
            console.log('errror')
            console.log(err);
            return;
        }
        console.log('hello4')
        console.log(buildings)
        console.log('hello5')
        return buildings
           
    });   console.log('hello6')
    }




getRecords().then(function(r){
    console.log('test')
    console.log(r)
})