Skip to content

Commit

Permalink
fix: bug in subscription auto abortion of SimplePool/NDK adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jiftechnify committed Jun 20, 2023
1 parent 1a157b0 commit 4fd8879
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions packages/adapter-ndk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,6 @@ class NDKAdapter implements NostrFetcherBase {
removeRelayListeners();
};

// handle subscription events
sub.on("event", (ndkEv: NDKEvent) => {
tx.send(ndkEv.rawEvent() as NostrEvent);
});
sub.on("eose", () => {
closeSub();
});

// auto abortion
let subAutoAbortTimer: NodeJS.Timer | undefined;
const resetAutoAbortTimer = () => {
Expand All @@ -176,6 +168,15 @@ class NDKAdapter implements NostrFetcherBase {
closeSub();
});

// handle subscription events
sub.on("event", (ndkEv: NDKEvent) => {
tx.send(ndkEv.rawEvent() as NostrEvent);
resetAutoAbortTimer();
});
sub.on("eose", () => {
closeSub();
});

// start subscription
sub.start();

Expand Down
17 changes: 9 additions & 8 deletions packages/adapter-nostr-tools/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,6 @@ class SimplePoolExt implements NostrFetcherBase {
removeRelayListeners();
};

// handle subscription events
sub.on("event", (ev: NostrEvent) => {
tx.send(ev);
});
sub.on("eose", () => {
closeSub();
});

// auto abortion
let subAutoAbortTimer: NodeJS.Timer | undefined;
const resetAutoAbortTimer = () => {
Expand All @@ -171,6 +163,15 @@ class SimplePoolExt implements NostrFetcherBase {
closeSub();
});

// handle subscription events
sub.on("event", (ev: NostrEvent) => {
tx.send(ev);
resetAutoAbortTimer();
});
sub.on("eose", () => {
closeSub();
});

return chIter;
}

Expand Down

0 comments on commit 4fd8879

Please sign in to comment.