diff --git a/lib/purchaseQueries.ts b/lib/purchaseQueries.ts index ecf4506..b85a745 100644 --- a/lib/purchaseQueries.ts +++ b/lib/purchaseQueries.ts @@ -115,7 +115,7 @@ export function getPurchasesForArticle(articleId: string, timeoutMs: number = 50 const sub = createSubscription(pool, [relayUrl], filters) let finished = false - const done = async () => { + const done = async (): Promise => { if (finished) { return } @@ -124,7 +124,7 @@ export function getPurchasesForArticle(articleId: string, timeoutMs: number = 50 resolve(results) } - sub.on('event', async (event: Event) => { + sub.on('event', async (event: Event): Promise => { const parsed = await parsePurchaseFromEvent(event) if (parsed?.articleId === articleId) { // Cache the parsed purchase @@ -155,7 +155,7 @@ export function getPurchasesByPayer(payerPubkey: string, timeoutMs: number = 500 const sub = createSubscription(pool, [relayUrl], filters) let finished = false - const done = async () => { + const done = async (): Promise => { if (finished) { return } @@ -164,7 +164,7 @@ export function getPurchasesByPayer(payerPubkey: string, timeoutMs: number = 500 resolve(results) } - sub.on('event', async (event: Event) => { + sub.on('event', async (event: Event): Promise => { const parsed = await parsePurchaseFromEvent(event) if (parsed) { // Cache the parsed purchase @@ -175,7 +175,9 @@ export function getPurchasesByPayer(payerPubkey: string, timeoutMs: number = 500 } }) - sub.on('eose', () => done()) + sub.on('eose', (): void => { + void done() + }) setTimeout(() => done(), timeoutMs).unref?.() }) } diff --git a/lib/sponsoringQueries.ts b/lib/sponsoringQueries.ts index 8d1c47f..f3934a5 100644 --- a/lib/sponsoringQueries.ts +++ b/lib/sponsoringQueries.ts @@ -113,7 +113,7 @@ export function getSponsoringByAuthor(authorPubkey: string, timeoutMs: number = const sub = createSubscription(pool, [relayUrl], filters) let finished = false - const done = async () => { + const done = async (): Promise => { if (finished) { return } @@ -122,7 +122,7 @@ export function getSponsoringByAuthor(authorPubkey: string, timeoutMs: number = resolve(results) } - sub.on('event', async (event: Event) => { + sub.on('event', async (event: Event): Promise => { const parsed = await parseSponsoringFromEvent(event) if (parsed?.authorPubkey === authorPubkey) { // Cache the parsed sponsoring @@ -133,7 +133,9 @@ export function getSponsoringByAuthor(authorPubkey: string, timeoutMs: number = } }) - sub.on('eose', () => done()) + sub.on('eose', (): void => { + void done() + }) setTimeout(() => done(), timeoutMs).unref?.() }) }