Files
pytchat-fork/pytchat/core_multithread/buffer.py
taizan-hokouto 16df63c14e Fix comments
2020-10-24 16:10:04 +09:00

41 lines
871 B
Python

import queue
class Buffer(queue.Queue):
'''
Buffer for storing chat data.
Parameter
---------
maxsize : int
Maximum number of chat blocks to be stored.
If it exceeds the maximum, the oldest chat block will be discarded.
'''
def __init__(self, maxsize=0):
super().__init__(maxsize=maxsize)
def put(self, item):
if item is None:
return
if super().full():
super().get_nowait()
else:
super().put(item)
def put_nowait(self, item):
if item is None:
return
if super().full():
super().get_nowait()
else:
super().put_nowait(item)
def get(self):
ret = []
ret.append(super().get())
while not super().empty():
ret.append(super().get())
return ret