@@ -29,22 +29,22 @@ class Batcher(Generic[T]):
2929
3030 # Triggers when 2 (or more) items are added
3131 batcher = Batcher(max_count=2)
32- assert batcher.add(["foo ", "bar ", "baz "])
33- assert batcher.flush() == ["foo ", "bar ", "baz "]
32+ assert batcher.add(["item1 ", "item2 ", "item3 "])
33+ assert batcher.flush() == ["item1 ", "item2 ", "item3 "]
3434
3535 # Triggers partially when 2 (or more) items are added
3636 batcher = Batcher(max_count=2)
37- assert batcher.add(["foo ", "bar ", "baz "])
38- assert batcher.flush(partial=True) == ["foo ", "bar "]
39- assert batcher.add("foobar ")
40- assert batcher.flush(partial=True) == ["baz ", "foobar "]
37+ assert batcher.add(["item1 ", "item2 ", "item3 "])
38+ assert batcher.flush(partial=True) == ["item1 ", "item2 "]
39+ assert batcher.add("item4 ")
40+ assert batcher.flush(partial=True) == ["item3 ", "item4 "]
4141
4242 # Trigger 2 seconds after the first add
4343 batcher = Batcher(max_window=2.0)
44- assert not batcher.add(["foo ", "bar ", "baz "])
44+ assert not batcher.add(["item1 ", "item2 ", "item3 "])
4545 time.sleep(2.1)
46- assert not batcher.add(["foobar "])
47- assert batcher.flush() == ["foo ", "bar ", "baz ", "foobar "]
46+ assert not batcher.add(["item4 "])
47+ assert batcher.flush() == ["item1 ", "item2 ", "item3 ", "item4 "]
4848 """
4949
5050 max_count : Optional [int ] = Field (default = None , description = "Maximum number of items" , ge = 0 )
@@ -108,6 +108,7 @@ def flush(self, *, partial=False) -> list[T]:
108108
109109 self ._last_batch_time = time .monotonic ()
110110 self ._triggered = False
111+ self ._check_batch_policy ()
111112
112113 return result
113114
0 commit comments