diff --git a/hexlib/misc.py b/hexlib/misc.py index 71338ca..5e6125d 100644 --- a/hexlib/misc.py +++ b/hexlib/misc.py @@ -1,5 +1,6 @@ import time +import atexit import siphash last_time_called = dict() @@ -25,6 +26,27 @@ def rate_limit(per_second): return decorate +def buffered(batch_size: int, flush_on_exit: bool = False): + + def decorate(func): + buffer = [] + if flush_on_exit: + atexit.register(func, buffer) + + def wrapper(*items): + + for item in items: + buffer.append(item) + + if len(buffer) >= batch_size: + func(buffer) + buffer.clear() + + return wrapper + + return decorate + + Key = b"0123456789ABCDEF" diff --git a/setup.py b/setup.py index e2bd840..6dd96d2 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="hexlib", - version="1.2", + version="1.3", description="Misc utility methods", author="simon987", author_email="me@simon987.net",