diff --git a/CHANGELOG.md b/CHANGELOG.md index 81803664ab4c9a4d00987f4e52c951c235cf8d7d..9ef5a7a8707ec34eb54e0a1948ab2e8efa5d9649 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 fd56a4d5ae1401bda2f3c094b12100faba076b84..20a9b6eb95fd052c4b988d782e56013d4c0775e0 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 e3f8aa66d724cb1cb013e2025d6e9856bb6fc3d4..ea99e782922ec381f8b0d6518eca7355e7e2d446 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 24353fe079a30b46e8ad2a70f911bd03c301a5b8..d13d8d875d5ec47861331f092bfc51aed2669174 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()