ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.36k stars 271 forks source link

Bad state: too many elements #667

Closed cntoss closed 6 months ago

cntoss commented 2 years ago

Below is an error on behaviorsubject when .sink.add called more than once this error is not always happen

sample code:

 //initialization
 final _orders = BehaviorSubject<String>();

//update
update() {
_order.sink.add('xyz');
}

if I called update() method several times then I got exception

Unhandled Exception: Bad state: Too many elements

0 Stream.single. (dart:async[/stream.dart:1354:11]())

1 _rootRunUnary (dart:async[/zone.dart:1434:47]())

2 _CustomZone.runUnary (dart:async[/zone.dart:1335:19]())

3 _CustomZone.runUnaryGuarded (dart:async[/zone.dart:1244:7]())

4 _BufferingStreamSubscription._sendData (dart:async[/stream_impl.dart:341:11]())

5 _BufferingStreamSubscription._add (dart:async[/stream_impl.dart:271:7]())

6 _MultiStreamController.addSync (dart:async[/stream_impl.dart:1129:36]())

7 _MultiControllerSink.add

package:rxdart/…/utils/forwarding_stream.dart:135

8 _StartWithStreamSink.onData

package:rxdart/…/transformers/start_with.dart:12

9 _rootRunUnary (dart:async[/zone.dart:1434:47]())

10 _CustomZone.runUnary (dart:async[/zone.dart:1335:19]())

11 _CustomZone.runUnaryGuarded (dart:async[/zone.dart:1244:7]())

12 _BufferingStreamSubscription._sendData (dart:async[/stream_impl.dart:3]()<…>

hoc081098 commented 2 years ago

Use Stream.first instead single

cntoss commented 2 years ago

I did not get it. if I do stream.first and then on streambuilder I did not get updated response on stream that means if I do _order.sink.add('hello'); I only get 'xyz' which is first value of stream.

hoc081098 commented 2 years ago

@cntoss please add some codes to reproduce this issue

feizhaojun commented 4 months ago

Have you resolved this? I get the same exception.

hoc081098 commented 4 months ago

Have you resolved this? I get the same exception.

Did you use behaviorSubject.single?