From c0ca5a6dcaa9f5d36a42cbc59d46c7344f014159 Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Sun, 29 Oct 2023 12:03:23 +0800 Subject: [PATCH] problem: infinite loop over events --- .../stores/nostrocket_state/master_state.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/lib/stores/nostrocket_state/master_state.ts b/src/lib/stores/nostrocket_state/master_state.ts index bd0e32f..36a7636 100644 --- a/src/lib/stores/nostrocket_state/master_state.ts +++ b/src/lib/stores/nostrocket_state/master_state.ts @@ -71,18 +71,23 @@ eose.subscribe((val)=>{ watchMempool(); } }) - const watchMempoolMutex = new Mutex(); + +const watchMempoolMutex = new Mutex(); async function watchMempool() { - let last = 0; + let lastNumberOfEventsHandled = 0; watchMempoolMutex.acquire().then(() => { eligibleForProcessing.subscribe(() => { //todo prevent this from infinitely looping. - changeStateMutex("state:244").then((release) => { - let current = get(consensusTipState); - let newstate = processSoftStateChangeReqeustsFromMempool(current, eligibleForProcessing); - consensusTipState.set(newstate); - release(); - }); + let eventsHandled = get(inState).size + if (eventsHandled > lastNumberOfEventsHandled) { + lastNumberOfEventsHandled = eventsHandled + changeStateMutex("state:244").then((release) => { + let current = get(consensusTipState); + let newstate = processSoftStateChangeReqeustsFromMempool(current, eligibleForProcessing); + consensusTipState.set(newstate); + release(); + }); + } }); }); }