for await in code example
Example 1: for await example
(async function() {
for await (let num of asyncIterable) {
console.log(num);
}
})();
// 0
// 1
// 2
Example 2: typescript foreach async await
export async function asyncForEach<T>(array: Array<T>, callback: (item: T, index: number) => void) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index);
}
}
await asyncForEach(receipts, async (eachItem) => {
await ...
})