Merge remote-tracking branch 'origin/main' into adam/add-ol2-options

This commit is contained in:
Adam Hathcock
2025-09-23 09:44:31 +01:00
41 changed files with 730 additions and 296 deletions
@@ -17,7 +17,7 @@ describe('BatchingQueue disposal', () => {
await queue.disposeAsync()
expect(processFunction).toHaveBeenCalledWith(items)
expect(processFunction).not.toHaveBeenCalled()
expect(queue.count()).toBe(0)
expect(queue.isDisposed()).toBe(true)
})
@@ -52,8 +52,6 @@ describe('BatchingQueue disposal', () => {
resolveProcess()
await disposePromise
expect(processFunction).toHaveBeenCalledTimes(2)
expect(processFunction).toHaveBeenCalledWith(items2)
expect(queue.count()).toBe(0)
expect(queue.isDisposed()).toBe(true)
})
@@ -1,4 +1,3 @@
import { CustomLogger } from '../types/functions.js'
import KeyedQueue from './keyedQueue.js'
/**
@@ -13,7 +12,6 @@ export default class BatchingQueue<T> {
#processFunction: (batch: T[]) => Promise<void>
#timeoutId: ReturnType<typeof setTimeout> | null = null
#isProcessing = false
#logger: CustomLogger
#disposed = false
#batchTimeout: number
@@ -41,12 +39,10 @@ export default class BatchingQueue<T> {
batchSize: number
maxWaitTime: number
processFunction: (batch: T[]) => Promise<void>
logger?: CustomLogger
}) {
this.#batchSize = params.batchSize
this.#processFunction = params.processFunction
this.#batchTimeout = params.maxWaitTime
this.#logger = params.logger || ((): void => {})
}
async disposeAsync(): Promise<void> {
@@ -106,10 +102,10 @@ export default class BatchingQueue<T> {
if (this.#isProcessing || this.#queue.size === 0) {
return
}
if (this.#disposed) return
this.#isProcessing = true
const batchToProcess = this.#getBatch(this.#batchSize)
if (this.#disposed) return
try {
await this.#processFunction(batchToProcess)