I know there are async, async* and sync* in Flutter. However, I only know when and how to use async, not async* and sync*.
I know that I need to mark async for the function when the function body has await, but when to mark async* or sync*?
What is the difference between these three? Also, when and how to use them? It would be better if you could share some sample code about async, async* and sync*.
Thanks a lot if someone can tell me what the difference is. Thank you in advance!
See the Dart language tour about Generators: https://dart.dev/guides/language/language-tour#generators
In short, sync* creates an Iterable, and async* creates a Stream, and both use yield to add one element, and yield* to splice an existing iterable or stream into the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With