File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -161,4 +161,32 @@ describe('Queue', () => {
161161 // - one tick for the await within the withCleanUp next()
162162 expect ( await sub . next ( ) ) . to . deep . equal ( { done : false , value : [ 4 ] } ) ;
163163 } ) ;
164+
165+ it ( 'should condense pushes during map into the same batch' , async ( ) => {
166+ let push ! : ( item : number ) => void ;
167+ const queue = new Queue < number > ( ( _push ) => {
168+ push = _push ;
169+ } ) ;
170+
171+ await resolveOnNextTick ( ) ;
172+ push ( 1 ) ;
173+ push ( 2 ) ;
174+
175+ const itemsToAdd = [ 3 , 4 ] ;
176+ const items : Array < number > = [ ] ;
177+ const sub = queue . subscribe ( ( batch ) => {
178+ for ( const item of batch ) {
179+ const itemToAdd = itemsToAdd . shift ( ) ;
180+ if ( itemToAdd !== undefined ) {
181+ push ( itemToAdd ) ;
182+ }
183+ items . push ( item ) ;
184+ }
185+ return items ;
186+ } ) ;
187+ expect ( await sub . next ( ) ) . to . deep . equal ( {
188+ done : false ,
189+ value : [ 1 , 2 , 3 , 4 ] ,
190+ } ) ;
191+ } ) ;
164192} ) ;
You can’t perform that action at this time.
0 commit comments