Debug client, pass timeout into reqmeister
This commit is contained in:
parent
baf51230ba
commit
4d05398be1
|
@ -1,13 +1,16 @@
|
|||
import { type Event, type Filter, matchFilters } from '@/deps.ts';
|
||||
import { Debug, type Event, type Filter, matchFilters } from '@/deps.ts';
|
||||
import * as pipeline from '@/pipeline.ts';
|
||||
import { activeRelays, pool } from '@/pool.ts';
|
||||
|
||||
import type { GetFiltersOpts } from '@/filter.ts';
|
||||
|
||||
const debug = Debug('ditto:client');
|
||||
|
||||
/** Get events from a NIP-01 filter. */
|
||||
function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts = {}): Promise<Event<K>[]> {
|
||||
if (opts.signal?.aborted) return Promise.resolve([]);
|
||||
if (!filters.length) return Promise.resolve([]);
|
||||
debug(JSON.stringify(filters));
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const results: Event[] = [];
|
||||
|
|
|
@ -52,7 +52,7 @@ function matchDittoFilters(filters: DittoFilter[], event: Event, data: EventData
|
|||
/** Get deterministic ID for a microfilter. */
|
||||
function getFilterId(filter: MicroFilter): string {
|
||||
if ('ids' in filter) {
|
||||
return stringifyStable({ ids: [filter.ids] });
|
||||
return stringifyStable({ ids: [filter.ids[0]] });
|
||||
} else {
|
||||
return stringifyStable({
|
||||
kinds: [filter.kinds[0]],
|
||||
|
|
|
@ -7,7 +7,7 @@ const debug = Debug('ditto:reqmeister');
|
|||
|
||||
interface ReqmeisterOpts {
|
||||
delay?: number;
|
||||
signal?: AbortSignal;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
type ReqmeisterQueueItem = [string, MicroFilter, WebSocket['url'][]];
|
||||
|
@ -34,7 +34,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: Event) => an
|
|||
}
|
||||
|
||||
async #perform() {
|
||||
const { delay } = this.#opts;
|
||||
const { delay, timeout = Time.seconds(1) } = this.#opts;
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
|
||||
const queue = this.#queue;
|
||||
|
@ -59,7 +59,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: Event) => an
|
|||
|
||||
if (filters.length) {
|
||||
debug(JSON.stringify(filters));
|
||||
const events = await client.getFilters(filters, { signal: this.#opts.signal });
|
||||
const events = await client.getFilters(filters, { signal: AbortSignal.timeout(timeout) });
|
||||
|
||||
for (const event of events) {
|
||||
this.encounter(event);
|
||||
|
@ -75,7 +75,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: Event) => an
|
|||
this.#queue.push([filterId, filter, relays]);
|
||||
return new Promise<Event>((resolve, reject) => {
|
||||
this.once(filterId, resolve);
|
||||
this.#promise.finally(reject);
|
||||
this.#promise.finally(() => setTimeout(reject, 0));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ class Reqmeister extends EventEmitter<{ [filterId: string]: (event: Event) => an
|
|||
|
||||
const reqmeister = new Reqmeister({
|
||||
delay: Time.seconds(1),
|
||||
signal: AbortSignal.timeout(Time.seconds(1)),
|
||||
timeout: Time.seconds(1),
|
||||
});
|
||||
|
||||
export { reqmeister };
|
||||
|
|
Loading…
Reference in New Issue