Something went wrong. Try again.
The Social Wire — an ATProto publication reader. thesocialwire.app
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142export class CursorSingleFlight { private active: | { token: symbol; feedKey: string; cursor: string; promise: Promise<unknown>; } | undefined;
run(args: { feedKey: string; cursor: string; request: () => Promise<unknown>; }): Promise<unknown> { if ( this.active?.feedKey === args.feedKey && this.active.cursor === args.cursor ) { return this.active.promise; }
const token = Symbol(args.cursor); const promise = Promise.resolve() .then(args.request) .finally(() => { if (this.active?.token === token) this.active = undefined; }); this.active = { token, feedKey: args.feedKey, cursor: args.cursor, promise, }; return promise; }
reset(): void { this.active = undefined; }}