如何解释这两种广播流之间的区别?

时间:2018-10-12 14:53:00

标签: stream dart

根据我创建广播stream / streamController的方式,结果是不同的。

使用StreamController.broadcast()

final sc = StreamController.broadcast();
final stream = sc.stream;
print(stream.isBroadcast);
stream.length.then(print);
stream.length.then(print);
sc..add('')..close();
stream.length.then(print);
stream.length.then(print);

我得到输出:

true
c0
d0
a1
b1

使用StreamController.stream.asBroadcastStream()

final sc = StreamController();
final stream = sc.stream.asBroadcastStream();
print(stream.isBroadcast);
stream.length.then(print);
stream.length.then(print);
sc..add('')..close();
stream.length.then(print);
stream.length.then(print);

我得到输出:

true
a1
b1
c1
d1

如何解释差异?

(我在DartPad SDK 2.0.0上进行了此测试)

0 个答案:

没有答案