acebase/spec/async-task-batch.spec.js
Ewout Stortenbeker 23fd876810
Indexes, query and load performance improvements (#156)
* new batched async task runner

* use new async task batcher

* improve tree (index) lookups for many entries

* unit test for batched async task runner

* chore: build
2022-09-17 15:29:41 +02:00

18 lines
699 B
JavaScript

const { AsyncTaskBatch } = require('../src/async-task-batch');
describe('Async task batches', () => {
it('works', async () => {
let currentIndex = 0, expectedResults = [];
const batch = new AsyncTaskBatch(10);
for (let i = 0; i < 1000; i++) {
batch.add(() => {
const ms = Math.floor(Math.random() * 10); // task to run between 0-10ms
expectedResults[currentIndex] = ms;
currentIndex++;
return new Promise((resolve) => setTimeout(() => resolve(ms), ms));
});
}
const results = await batch.finish();
expect(results).toEqual(expectedResults);
}, 10e3);
});