From 119cb6248b303d85c67f1462c3630ff1c4b6e94c Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 9 Feb 2026 10:02:02 -0800 Subject: [PATCH] Fix task queue --- packages/app/src/session.ts | 13 +++---------- packages/lib/src/TaskQueue.ts | 28 ++++++++++++++++------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/app/src/session.ts b/packages/app/src/session.ts index 12f1f08..ca35cc5 100644 --- a/packages/app/src/session.ts +++ b/packages/app/src/session.ts @@ -6,7 +6,6 @@ import { Wallet, WRAP, getPubkeyTagValues, - HashedEvent, StampedEvent, SignedEvent, getPubkey, @@ -323,8 +322,6 @@ export const unwrapAndStore = async (wrap: SignedEvent) => { return cached } - let result: {rumor: HashedEvent; recipient: string} | undefined - // Next, try to decrypt as the recipient for (const recipient of getPubkeyTagValues(wrap.tags)) { const signer = getSignerFromPubkey(recipient) @@ -333,16 +330,12 @@ export const unwrapAndStore = async (wrap: SignedEvent) => { try { const rumor = await Nip59.fromSigner(signer).unwrap(wrap) - result = {rumor, recipient} + wrapManager.add({wrap, rumor, recipient}) + + return rumor } catch (e) { failedUnwraps.add(wrap.id) } } } - - if (result) { - wrapManager.add({wrap, ...result}) - - return result.rumor - } } diff --git a/packages/lib/src/TaskQueue.ts b/packages/lib/src/TaskQueue.ts index d6b87fb..1a44311 100644 --- a/packages/lib/src/TaskQueue.ts +++ b/packages/lib/src/TaskQueue.ts @@ -39,22 +39,26 @@ export class TaskQueue { this.isProcessing = true setTimeout(async () => { - for (const item of this.items.splice(0, this.options.batchSize)) { - try { - for (const subscriber of this._subs) { - subscriber(item) + if (this.isPaused) { + this.isProcessing = false + } else { + for (const item of this.items.splice(0, this.options.batchSize)) { + try { + for (const subscriber of this._subs) { + subscriber(item) + } + + await this.options.processItem(item) + } catch (e) { + console.error(e) } - - await this.options.processItem(item) - } catch (e) { - console.error(e) } - } - this.isProcessing = false + this.isProcessing = false - if (this.items.length > 0) { - this.process() + if (this.items.length > 0) { + this.process() + } } }, this.options.batchDelay) }