'async await not waiting for object to fill axios.get

I have an object called move_dict and am using the method get_learned_by_pokemon() to fill it. In getPokes() I call the get_learned_by_pokemon() and expect move_dict to be filled. However it is empty.

function move(){
    let move_dict = {}
    let db_data = JSON.parse(fs.readFileSync('pokes.json', 'utf8'));
    async function get_learned_by_pokemon(curr_move, move_dict, current_poke){
        response = await axios.get('https://pokeapi.co/api/v2/move/'.concat(curr_move))

        let learned_by_pokemons = []
        for (let k = 0; k < response.data.learned_by_pokemon.length; k++){
            learned_by_pokemons.push(response.data.learned_by_pokemon[k].name)
        }
        // pass
        if (learned_by_pokemons.includes(current_poke)){move_dict[current_poke].pass.push(curr_move)}
        // fail
        else{move_dict[current_poke].fail.push(curr_move)}

    }
    function getPokes(){
        //iterate through all pokemon
        for (let i = 0; i < db_data.length; i++){
            let current_poke = db_data[i].name
            let moves = db_data[i].moves
            move_dict[current_poke] = {pass: [], fail: []}
            //iterate through all moves of pokemon
            for (let j = 0; j < moves.length; j++){
                let curr_move = moves[j]
                //get data on current move
                get_learned_by_pokemon(curr_move, move_dict, current_poke)
            }
        }
    }

    getPokes()
}

I've also used an await before the Axios.get() . I'd like to know why move_dict is not filling and I'd like to overcome this problem without using a setTimeout()



Solution 1:[1]

there are 2 wrong with your code. 1: where do you call getPokes() ? 2: get_learned_by_pokemon is async function so you have to use await if you want to wait for it done

Solution 2:[2]

In Oracle, "user" and "schema" are effectively the same thing. In most cases (unless you are a DBA or have other specific elevated privileges) you must connect directly to the user/schema you want to work with. There is no way to change user/schema once your connection is established; you would have to reconnect with new credentials.

If you do have elevated privileges to work with objects in schemas other than the one you connected to (e.g. create any table), you can do that by fully qualifying the object name (e.g. schema_name.table_name) in your DDL, DML, or SQL. You would not need to reconnect first.

In cases where there is a shared application schema/user, proxy user access can be configured by the DBA that will allow you to connect as another user using your personal credentials and avoid having to share common passwords or keys, but you would still be connected to a specific schema/user.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phạm Vỹ
Solution 2 pmdba