From e92ac4877f8a8be74f347a0d305334204887dad6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Mon, 14 Jun 2021 12:11:35 +0200
Subject: [PATCH] add put_many to PeekableQueue

---
 CHANGELOG.md                         |  1 +
 satella/__init__.py                  |  2 +-
 satella/coding/concurrent/queue.py   | 13 +++++++++++++
 tests/test_coding/test_concurrent.py |  8 ++++++++
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 81803664..9ef5a7a8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,3 +2,4 @@
 
 * added `synchronize_on_attribute` for `Monitor`
 * added `FutureCollection`
+* added `put_many` to `PeekableQueue`
diff --git a/satella/__init__.py b/satella/__init__.py
index fd56a4d5..20a9b6eb 100644
--- a/satella/__init__.py
+++ b/satella/__init__.py
@@ -1 +1 @@
-__version__ = '2.17.6a3'
+__version__ = '2.17.6a4'
diff --git a/satella/coding/concurrent/queue.py b/satella/coding/concurrent/queue.py
index e3f8aa66..ea99e782 100644
--- a/satella/coding/concurrent/queue.py
+++ b/satella/coding/concurrent/queue.py
@@ -32,6 +32,19 @@ class PeekableQueue(tp.Generic[T]):
             self.queue.append(item)
         self.inserted_condition.notify()
 
+    def put_many(self, items: tp.Sequence[T]) -> None:
+        """
+        Put multiple items
+
+        :param items: sequence of items to put
+        """
+        with self.lock:
+            items_count = 0
+            for item in items:
+                items_count += 1
+                self.queue.append(item)
+        self.inserted_condition.notify(items_count)
+
     @rethrow_as(WouldWaitMore, Empty)
     def __get(self, timeout, item_getter) -> T:
         self.lock.acquire()
diff --git a/tests/test_coding/test_concurrent.py b/tests/test_coding/test_concurrent.py
index 24353fe0..d13d8d87 100644
--- a/tests/test_coding/test_concurrent.py
+++ b/tests/test_coding/test_concurrent.py
@@ -169,6 +169,14 @@ class TestConcurrent(unittest.TestCase):
         d = si.issue()
         self.assertGreater(d, c)
 
+    def test_peekable_queue_put_many(self):
+        pkb = PeekableQueue()
+
+        pkb.put_many([1, 2])
+
+        self.assertEqual(pkb.get(), 1)
+        self.assertEqual(pkb.get(), 2)
+
     def test_peekable_queue(self):
         pkb = PeekableQueue()
 
-- 
GitLab