简体   繁体   中英

Is there any difference between using async* and yield* or not on returning FirebaseFirestore QuerySnapshot

Is there any difference between the first case and the second case?

1.

Stream<QuerySnapshot> streamUsersOne() async* {
  yield* FirebaseFirestore.instance.collection('users').snapshots();
}

2.

Stream<QuerySnapshot> streamUsersTwo() {
  return FirebaseFirestore.instance.collection('users').snapshots();
}

This first one(async* and yield) is used when you are creating your own Stream and it has no need to use it here because the snapshots method has already return type of Stream. you can watch this clip to learn more about how to create a stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM