Add policy for deferring messages when auth has failed

This commit is contained in:
Jon Staab
2025-03-21 14:12:50 -07:00
parent be3ce11110
commit 62f0caff1d
6 changed files with 221 additions and 97 deletions
+8 -4
View File
@@ -1,4 +1,4 @@
import {yieldThread} from "./Tools.js"
import {remove, yieldThread} from "./Tools.js"
export type TaskQueueOptions<Item> = {
batchSize: number
@@ -17,13 +17,19 @@ export class TaskQueue<Item> {
this.process()
}
remove(item: Item) {
this.items = remove(item, this.items)
}
async process() {
if (this.isProcessing || this.isPaused) {
if (this.isProcessing || this.isPaused || this.items.length == 0) {
return
}
this.isProcessing = true
await yieldThread()
for (const item of this.items.splice(0, this.options.batchSize)) {
try {
await this.options.processItem(item)
@@ -35,8 +41,6 @@ export class TaskQueue<Item> {
this.isProcessing = false
if (this.items.length > 0) {
await yieldThread()
this.process()
}
}