add channel reusing and cancellation to README.

This commit is contained in:
fiatjaf 2021-05-22 21:24:19 -03:00
parent e2956ab937
commit fc4ddad068
1 changed files with 15 additions and 5 deletions

View File

@ -26,14 +26,24 @@ pool.sub({cb: onEvent, filter: {author: '<hex>'}})
// or bulk follow
pool.sub({cb:(event, relay) => {...}, filter: {authors: ['<hex1>', '<hex2>', ..., '<hexn>']}})
// reuse a subscription channel
const mySubscription = pool.sub({cb: ..., filter: ....})
mySubscription.sub({filter: ....})
mySubscription.sub({cb: ...})
mySubscription.unsub()
// get specific event
pool.sub({cb: (event, relay) => {...}, filter: {id: '<hex>'}})
// or get a specific event plus all the events that reference it in the 'e' tag
pool.sub({
cb: (event, relay) => {...},
filter: [{id: '<hex>'}, {'#e': '<hex>'}]
const specificChannel = pool.sub({
cb: (event, relay) => {
console.log('got specific event from relay', event, relay)
specificChannel.unsub()
},
filter: {id: '<hex>'}
})
// or get a specific event plus all the events that reference it in the 'e' tag
pool.sub({ cb: (event, relay) => { ... }, filter: [{id: '<hex>'}, {'#e': '<hex>'}] })
// get all events
pool.sub({cb: (event, relay) => {...}, filter: {}})