turn .publish() into a normal async function returning a promise.

this simplifies the code and makes the API more intuitive.

we used to need the event emitter thing because we were subscribing to the same relay
to check if the event had been published, but that is not necessary now that we assume
an OK response will always come.

closes https://github.com/nbd-wtf/nostr-tools/issues/262
This commit is contained in:
fiatjaf
2023-07-30 12:19:11 -03:00
committed by fiatjaf_
parent 17590cce91
commit 9d690814ca
4 changed files with 64 additions and 101 deletions

View File

@@ -108,13 +108,7 @@ let event = {
event.id = getEventHash(event)
event.sig = getSignature(event, sk)
let pub = relay.publish(event)
pub.on('ok', () => {
console.log(`${relay.url} has accepted our event`)
})
pub.on('failed', reason => {
console.log(`failed to publish to ${relay.url}: ${reason}`)
})
await relay.publish(event)
let events = await relay.list([{kinds: [0, 1]}])
let event = await relay.get({