@@ -47,6 +47,61 @@ void main() {
4747 });
4848 });
4949
50+ test ('increases delay after pause' , () {
51+ fakeAsync ((control) {
52+ final source = StreamController <UpdateNotification >(sync : true );
53+ final events = < UpdateNotification > [];
54+
55+ final sub = UpdateNotification .throttleStream (source.stream, timeout)
56+ .listen (null );
57+ sub.onData ((event) {
58+ events.add (event);
59+ sub.pause ();
60+ });
61+
62+ source.add (UpdateNotification ({'a' }));
63+ control.elapse (timeout);
64+ expect (events, hasLength (1 ));
65+
66+ // Assume the stream stays paused for the timeout window that would
67+ // be created after emitting the notification.
68+ control.elapse (timeout * 2 );
69+ source.add (UpdateNotification ({'b' }));
70+ control.elapse (timeout * 2 );
71+
72+ // A full timeout needs to pass after resuming before a new item is
73+ // emitted.
74+ sub.resume ();
75+ expect (events, hasLength (1 ));
76+
77+ control.elapse (halfTimeout);
78+ expect (events, hasLength (1 ));
79+ control.elapse (halfTimeout);
80+ expect (events, hasLength (2 ));
81+ });
82+ });
83+
84+ test ('does not introduce artificial delay in pause' , () {
85+ fakeAsync ((control) {
86+ final source = StreamController <UpdateNotification >(sync : true );
87+ final events = < UpdateNotification > [];
88+
89+ final sub = UpdateNotification .throttleStream (source.stream, timeout)
90+ .listen (events.add);
91+
92+ // Await the initial delay
93+ control.elapse (timeout);
94+
95+ sub.pause ();
96+ source.add (UpdateNotification ({'a' }));
97+ // Resuming should not introduce a timeout window because no window
98+ // was active when the stream was paused.
99+ sub.resume ();
100+ control.flushMicrotasks ();
101+ expect (events, hasLength (1 ));
102+ });
103+ });
104+
50105 test ('merges events' , () {
51106 fakeAsync ((control) {
52107 final source = StreamController <UpdateNotification >(sync : true );
0 commit comments