Skip to content

Commit

Permalink
problem: infinite loop over events
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Oct 29, 2023
1 parent d0e716e commit c0ca5a6
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lib/stores/nostrocket_state/master_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
});
});
}
Expand Down

0 comments on commit c0ca5a6

Please sign in to comment.