Skip to content

Commit

Permalink
fix yieldThread memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
syusui-s authored and fiatjaf committed Dec 30, 2023
1 parent da51418 commit 4cfc67e
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions helpers.ts
Original file line number Diff line number Diff line change
@@ -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<void>(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()
})
Expand Down

0 comments on commit 4cfc67e

Please sign in to comment.