fix fix yield.

This commit is contained in:
fiatjaf 2023-12-20 10:49:08 -03:00
parent 8625d45152
commit 0cc3c02d84
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
3 changed files with 12 additions and 9 deletions

View File

@ -8,6 +8,8 @@ const entryPoints = fs
file =>
file.endsWith('.ts') &&
file !== 'core.ts' &&
file !== 'test-helpers.ts' &&
file !== 'helpers.ts' &&
!file.endsWith('.test.ts') &&
fs.statSync(join(process.cwd(), file)).isFile(),
)

9
helpers.ts Normal file
View File

@ -0,0 +1,9 @@
export async function yieldThread() {
return new Promise(resolve => {
const ch = new MessageChannel()
// @ts-ignore (typescript thinks this property should be called `addListener`, but in fact it's `addEventListener`)
ch.port1.addEventListener('message', resolve)
ch.port2.postMessage(0)
ch.port1.start()
})
}

View File

@ -5,6 +5,7 @@ import { matchFilters, type Filter } from './filter.ts'
import { getHex64, getSubscriptionId } from './fakejson.ts'
import { Queue, normalizeURL } from './utils.ts'
import { nip42 } from './index.ts'
import { yieldThread } from './helpers.ts'
export function relayConnect(url: string) {
const relay = new Relay(url)
@ -12,15 +13,6 @@ export function relayConnect(url: string) {
return relay
}
async function yieldThread() {
return new Promise((resolve) => {
const ch = new MessageChannel();
ch.port1.addEventListener('message', () => resolve());
ch.port2.postMessage(0);
ch.port1.start();
});
}
export class Relay {
public readonly url: string
private _connected: boolean = false