根据我创建广播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上进行了此测试)