'How to call an async API fully synchronously within a loop in Dart?
How to call an async API fully synchronously within a loop in Dart?
For example, if I have
for(...) {
await doSomethingLongAsync();
}
as I understand, doSomethingLongAsync() will be invoked sequentionally but asynchronously on each iteration of the loop, i.e. each subsequent iteration of the loop will asynchronously call doSomethingLongAsync() even before the call of the previous iteration completes.
What I need is to make sure that a subsequent iteration of the loop does not invoke doSomethingLongAsync() until the previous iteration's invokation of the same function fully completes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|