fix fix yield.
This commit is contained in:
parent
8625d45152
commit
0cc3c02d84
2
build.js
2
build.js
|
@ -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(),
|
||||
)
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
}
|
10
relay.ts
10
relay.ts
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue