From 4cfc67e294ebd8d10288351d75fdd15e73ca9360 Mon Sep 17 00:00:00 2001 From: Shusui MOYATANI Date: Sat, 30 Dec 2023 18:30:30 +0900 Subject: [PATCH] fix yieldThread memory leak --- helpers.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/helpers.ts b/helpers.ts index ca5fb5d6..3457fdad 100644 --- a/helpers.ts +++ b/helpers.ts @@ -1,10 +1,15 @@ import { verifiedSymbol, type Event, type Nostr, VerifiedEvent } from './core.ts' export async function yieldThread() { - return new Promise(resolve => { + return new Promise(resolve => { const ch = new MessageChannel() + const handler = () => { + // @ts-ignore (typescript thinks this property should be called `removeListener`, but in fact it's `removeEventListener`) + ch.port1.removeEventListener('message', handler) + resolve() + } // @ts-ignore (typescript thinks this property should be called `addListener`, but in fact it's `addEventListener`) - ch.port1.addEventListener('message', resolve) + ch.port1.addEventListener('message', handler) ch.port2.postMessage(0) ch.port1.start() })