| 2 | |
| 3 | |
| 4 | class AsyncQueue: |
| 5 | def __init__(self): |
| 6 | self.datas = [] |
| 7 | self.event = asyncio.Event() |
| 8 | self.lock = asyncio.Lock() |
| 9 | |
| 10 | async def wait_to_ready(self): |
| 11 | try: |
| 12 | await asyncio.wait_for(self.event.wait(), timeout=3) |
| 13 | except asyncio.TimeoutError: |
| 14 | pass |
| 15 | |
| 16 | async def get_all_data(self): |
| 17 | async with self.lock: |
| 18 | self.event.clear() |
| 19 | ans = self.datas |
| 20 | self.datas = [] |
| 21 | return ans |
| 22 | |
| 23 | async def put(self, obj): |
| 24 | async with self.lock: |
| 25 | self.datas.append(obj) |
| 26 | self.event.set() |
| 27 | return |
| 28 | |
| 29 | async def wait_to_get_all_data(self): |
| 30 | await self.wait_to_ready() |
| 31 | handle_list = await self.get_all_data() |
| 32 | return handle_list |
no outgoing calls
no test coverage detected