From 332b6e40d37a1dee36a05e3c01ec98e512c038bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@ericsson.com>
Date: Wed, 18 Sep 2024 12:13:08 +0200
Subject: [PATCH] added __len__ to PeekableQueue

---
 CHANGELOG.md                       |  3 ++-
 satella/coding/concurrent/queue.py | 11 ++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d912699e..a32cf759 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
-# v.25.a3
+# v.25.a7
 
 * fixed circular import
+* added __len__ to PeekableQueue
 
 # v2.25.5
 
diff --git a/satella/coding/concurrent/queue.py b/satella/coding/concurrent/queue.py
index 8df1a49d..fce6a064 100644
--- a/satella/coding/concurrent/queue.py
+++ b/satella/coding/concurrent/queue.py
@@ -13,13 +13,14 @@ class PeekableQueue(tp.Generic[T]):
     """
     A thread-safe FIFO queue that supports peek()ing for elements.
     """
-    __slots__ = ('queue', 'lock', 'inserted_condition')
+    __slots__ = ('queue', 'lock', 'inserted_condition', 'items_count')
 
     def __init__(self):
         super().__init__()
         self.queue = collections.deque()
         self.lock = threading.Lock()
         self.inserted_condition = Condition()
+        self.items_count = 0
 
     def put(self, item: T) -> None:
         """
@@ -29,6 +30,7 @@ class PeekableQueue(tp.Generic[T]):
         """
         with self.lock:
             self.queue.append(item)
+            self.items_count += 1
         self.inserted_condition.notify()
 
     def put_many(self, items: tp.Sequence[T]) -> None:
@@ -40,7 +42,7 @@ class PeekableQueue(tp.Generic[T]):
         with self.lock:
             items_count = 0
             for item in items:
-                items_count += 1
+                self.items_count += 1
                 self.queue.append(item)
         self.inserted_condition.notify(items_count)
 
@@ -114,4 +116,7 @@ class PeekableQueue(tp.Generic[T]):
         guarantee that a subsequent get() will not block.
         :return: approximate size of the queue
         """
-        return len(self.queue)
+        return self.items_count
+
+    def __len__(self):
+        return self.items_count
\ No newline at end of file
-- 
GitLab