pipeline: pass signal down to everything that accepts it

This commit is contained in:
Alex Gleason 2024-01-22 14:31:52 -06:00
parent c5e7b3bf0c
commit 8494bd5f67
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 6 additions and 5 deletions

View File

@ -25,6 +25,7 @@ const debug = Debug('ditto:pipeline');
* It is idempotent, so it can be called multiple times for the same event. * It is idempotent, so it can be called multiple times for the same event.
*/ */
async function handleEvent(event: Event): Promise<void> { async function handleEvent(event: Event): Promise<void> {
const signal = AbortSignal.timeout(5000);
if (!(await verifySignatureWorker(event))) return; if (!(await verifySignatureWorker(event))) return;
const wanted = reqmeister.isWanted(event); const wanted = reqmeister.isWanted(event);
if (await encounterEvent(event)) return; if (await encounterEvent(event)) return;
@ -36,9 +37,9 @@ async function handleEvent(event: Event): Promise<void> {
processDeletions(event), processDeletions(event),
trackRelays(event), trackRelays(event),
trackHashtags(event), trackHashtags(event),
fetchRelatedEvents(event, data), fetchRelatedEvents(event, data, signal),
processMedia(event, data), processMedia(event, data),
payZap(event, data), payZap(event, data, signal),
streamOut(event, data), streamOut(event, data),
broadcast(event, data), broadcast(event, data),
]); ]);
@ -143,9 +144,9 @@ function trackRelays(event: Event) {
} }
/** Queue related events to fetch. */ /** Queue related events to fetch. */
function fetchRelatedEvents(event: Event, data: EventData) { function fetchRelatedEvents(event: Event, data: EventData, signal: AbortSignal) {
if (!data.user) { if (!data.user) {
reqmeister.req({ kinds: [0], authors: [event.pubkey] }).catch(() => {}); reqmeister.req({ kinds: [0], authors: [event.pubkey] }, { signal }).catch(() => {});
} }
for (const [name, id, relay] of event.tags) { for (const [name, id, relay] of event.tags) {
if (name === 'e' && !memorelay.count([{ ids: [id] }])) { if (name === 'e' && !memorelay.count([{ ids: [id] }])) {
@ -163,7 +164,7 @@ function processMedia({ tags, pubkey }: Event, { user }: EventData) {
} }
/** Emit Nostr Wallet Connect event from zaps so users may pay. */ /** Emit Nostr Wallet Connect event from zaps so users may pay. */
async function payZap(event: Event, data: EventData, signal = AbortSignal.timeout(5000)) { async function payZap(event: Event, data: EventData, signal: AbortSignal) {
if (event.kind !== 9734 || !data.user) return; if (event.kind !== 9734 || !data.user) return;
const lnurl = event.tags.find(([name]) => name === 'lnurl')?.[1]; const lnurl = event.tags.find(([name]) => name === 'lnurl')?.[1];