简体   繁体   English

在返回 FirebaseFirestore QuerySnapshot 时使用 async* 和 yield* 有什么区别吗

[英]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. 1.

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

2. 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.第一个(async* 和 yield)在您创建自己的 Stream 时使用,这里不需要使用它,因为 snapshots 方法已经返回 Stream 类型。 you can watch this clip to learn more about how to create a stream.您可以观看此 剪辑以了解有关如何创建流的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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