Closed timcreatedit closed 1 month ago
This is normal.
container.pump()
waits for providers to rebuild and get disposed.
It doesn't wait for Streams/Futures to complete if you have any pending task.
StreamController.add
emits its value asynchronously. When you first call container.pump()
, the value isn't emitted yet. So no provider rebuilds initially.
The second container.pump()
works because due to the first await
, your Stream finally emitted something, so a provider correctly has to rebuild now.
You can verify this quickly by changing:
- streamController = StreamController.broadcast();
+ streamController = StreamController.broadcast(sync: true);
With this, both tests now pass because the emit is now synchronous.
So ultimately the issue isn't with container.pump
, but your stream and streamController.add
.
Describe the bug When writing tests for a project I couldn't get tests to pass until I called
.pump()
twice in a row. This took me a long time to find, I tried to build the simplest example of what we're trying to do below, I think it's easier to see in code than whatever explanation I would come up with.To Reproduce
Expected behavior Calling
container.pump()
after adding a new value to the Stream should consider that new value. Furthermore, the waycontainer.pump()
is explained, calling it multiple times in a row should never be different from calling it once in my opinion.