Why a different result in the following cases? The first example works correctly, returns an array of three elements [\"qwe\", \"rty\", \"asd\"]. Second example
Concurrency. Or more precisely: A non atomic modification of values.
First of all, the values.concat(...) get evaluated, at that time values is an empty array. Then all the functions await. Then, all the values = get run, concatenating the awaited element to the empty array, and assigning those arrays with one value to values. The last resolved value wins.
To fix:
await Promise.all(
keys.map(
async key => {
const el = await this.getValue(key); // async operation
values = values.concat(el); // atomic update
}
)
);