mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
fix fix yield.
This commit is contained in:
2
build.js
2
build.js
@@ -8,6 +8,8 @@ const entryPoints = fs
|
|||||||
file =>
|
file =>
|
||||||
file.endsWith('.ts') &&
|
file.endsWith('.ts') &&
|
||||||
file !== 'core.ts' &&
|
file !== 'core.ts' &&
|
||||||
|
file !== 'test-helpers.ts' &&
|
||||||
|
file !== 'helpers.ts' &&
|
||||||
!file.endsWith('.test.ts') &&
|
!file.endsWith('.test.ts') &&
|
||||||
fs.statSync(join(process.cwd(), file)).isFile(),
|
fs.statSync(join(process.cwd(), file)).isFile(),
|
||||||
)
|
)
|
||||||
|
|||||||
9
helpers.ts
Normal file
9
helpers.ts
Normal 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()
|
||||||
|
})
|
||||||
|
}
|
||||||
10
relay.ts
10
relay.ts
@@ -5,6 +5,7 @@ import { matchFilters, type Filter } from './filter.ts'
|
|||||||
import { getHex64, getSubscriptionId } from './fakejson.ts'
|
import { getHex64, getSubscriptionId } from './fakejson.ts'
|
||||||
import { Queue, normalizeURL } from './utils.ts'
|
import { Queue, normalizeURL } from './utils.ts'
|
||||||
import { nip42 } from './index.ts'
|
import { nip42 } from './index.ts'
|
||||||
|
import { yieldThread } from './helpers.ts'
|
||||||
|
|
||||||
export function relayConnect(url: string) {
|
export function relayConnect(url: string) {
|
||||||
const relay = new Relay(url)
|
const relay = new Relay(url)
|
||||||
@@ -12,15 +13,6 @@ export function relayConnect(url: string) {
|
|||||||
return relay
|
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 {
|
export class Relay {
|
||||||
public readonly url: string
|
public readonly url: string
|
||||||
private _connected: boolean = false
|
private _connected: boolean = false
|
||||||
|
|||||||
Reference in New Issue
Block a user