Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

async* dart

What does async * mean in DART?

You add the async* keyword to make a function that returns 
a bunch of future values one at a time which are returned 
using keyword yield (which is used to return a value without
terminating the function execution)!

The results are wrapped in a Stream. An Example could be:

Stream<int> myStream() async* {
  //wait for Duration of 3 Secs and yield a value,
  for (int i = 0; i < 6; i++) {
    await Future.delayed(Duration(seconds: 3));
    yield i;
  }
}

void main() {
  Stream<int> instanceStream = myStream();

  instanceStream.listen((data) {
    print(data);
  });
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #dart
ADD COMMENT
Topic
Name
8+1 =