How to make iterator usable inside async callback function

Erroneous code can you spot why this usage of key will lead to bugs

Correct Writing