Skip to main content

Use await Inside Loop

You can call await to each item in a list’s looping.

for (var item in myList) {
  await callOther(item);
}
await Future.forEach(myList, (item) async {
  await anotherFutureFunction(item);
});
await searchRead(tableStockMove, args, params).then((items) async {
  for (var i = 0; i < items.length; i++) {
    StockMove move = StockMove.fromJson(items[i]);
    move.product = await searchProductById(move.product_id[0]!);
    response.stockMoves!.add(move);
  }
  response.success = ResponseStatus.success;
})

By continuing to use the site, you agree to the use of cookies.