From 3be2f986a838c30f5b6ab91ad05662aad23ada16 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Fri, 6 Jun 2025 06:17:26 +0200 Subject: [PATCH] Add batch_size/0 and batch_size_fun/0 types --- lib/broadway.ex | 12 ++++++++++++ lib/broadway/options.ex | 1 + 2 files changed, 13 insertions(+) diff --git a/lib/broadway.ex b/lib/broadway.ex index 907697f..1dd951f 100644 --- a/lib/broadway.ex +++ b/lib/broadway.ex @@ -843,6 +843,18 @@ defmodule Broadway do @type on_start() :: {:ok, pid()} | :ignore | {:error, {:already_started, pid()} | term()} @type name :: atom() | {:via, module(), term()} + @typedoc """ + A function used to dynamically determine the batch size. + """ + @typedoc since: "1.3.0" + @type batch_size_fun() :: (Message.t(), acc :: term() -> {:emit | :cont, acc :: term()}) + + @typedoc """ + Value for the `:batch_size` option. + """ + @typedoc since: "1.3.0" + @type batch_size() :: pos_integer() | {initial_acc :: term(), batch_size_fun()} + @doc """ Invoked for preparing messages before handling (if defined). diff --git a/lib/broadway/options.ex b/lib/broadway/options.ex index 0cd72c4..770a660 100644 --- a/lib/broadway/options.ex +++ b/lib/broadway/options.ex @@ -231,6 +231,7 @@ defmodule Broadway.Options do ], batch_size: [ type: {:custom, __MODULE__, :validate_batch_size, []}, + type_doc: "`t:batch_size/0`", default: 100, doc: """ The size of the generated batches. Default value is `100`. It is typically an