Flow.repeatSync keeps calling a function, yielding the results one-by-one as a generator. This is the synchronous version.
There’s also an asynchronous version, Flow.repeat .
Instead of using for await you can use JS’s in-built Array.fromAsync:
repeat allows you to add delays when looping:
To revisit the earlier example, this will get up to five random numbers, with one second delay between each.
Advanced
repeat will stop if its source stops. It will also stop if the source returns undefined. If you want to allow this, pass in allowUndefined: true as an option.
The options allow you to be notified when the repeat first starts going, or when it is complete: