I have a problem on how to properly make a inifite stream of data to stop beeing added to a subject. Like the example below:
void main() async {
var infinite = Stream.periodic(0.5.seconds, (it) => it);
var subject = BehaviorSubject<int>();
subject.addStream(infinite);
subject.listen(print);
await Future.delayed(Duration(milliseconds: 1000));
await subject.close(); //It will not allow me to close the subject
}
The infite
is a , well, infinite source of data. It will never emits a close
event. So, how to properly close the subject
since it will never finish to receive data?
Edit: the solution proposed on Bad state: You cannot close the subject while items are being added from addStream in flutter doesn't work simply because drain
never returns.