Skip to content

Commit

Permalink
avoid copying the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
laffra committed Jan 24, 2024
1 parent 783bf1f commit 13f583e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ltk/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ def match(self, message, receiver, receiver_topic, handler):
return handled

def process_queue(self):
for key, message in list(self.queue.items()):
handled = []
for key, message in self.queue.items():
if any(self.match(message, *subscriber) for subscriber in self.subscribers):
del self.queue[key] # remove the message from the queue
handled.append(key)
for key in handled:
del self.queue[key] # remove the message from the queue

def publish(self, sender, receiver, topic, data):
key = f"{_name}-{time.time()}"
Expand Down

0 comments on commit 13f583e

Please sign in to comment.