Skip to content
Snippets Groups Projects
Commit e92ac487 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add put_many to PeekableQueue

parent bb213f4d
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
* added `synchronize_on_attribute` for `Monitor` * added `synchronize_on_attribute` for `Monitor`
* added `FutureCollection` * added `FutureCollection`
* added `put_many` to `PeekableQueue`
__version__ = '2.17.6a3' __version__ = '2.17.6a4'
...@@ -32,6 +32,19 @@ class PeekableQueue(tp.Generic[T]): ...@@ -32,6 +32,19 @@ class PeekableQueue(tp.Generic[T]):
self.queue.append(item) self.queue.append(item)
self.inserted_condition.notify() 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) @rethrow_as(WouldWaitMore, Empty)
def __get(self, timeout, item_getter) -> T: def __get(self, timeout, item_getter) -> T:
self.lock.acquire() self.lock.acquire()
......
...@@ -169,6 +169,14 @@ class TestConcurrent(unittest.TestCase): ...@@ -169,6 +169,14 @@ class TestConcurrent(unittest.TestCase):
d = si.issue() d = si.issue()
self.assertGreater(d, c) 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): def test_peekable_queue(self):
pkb = PeekableQueue() pkb = PeekableQueue()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment