Skip to content

Commit 27c907e

Browse files
committed
add test
1 parent 19684da commit 27c907e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/execution/__tests__/Queue-test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)