@@ -99,14 +99,18 @@ defmodule Buffer do
9999 ## Options
100100
101101 * `:partition` - The specific partition to dump. Defaults to `:all`.
102+
103+ * `:timeout` - The timeout for the GenServer call in milliseconds. Defaults to `5000`.
102104 """
103105 @ spec dump ( GenServer . server ( ) , keyword ( ) ) :: { :ok , list ( ) } | { :error , atom ( ) }
104106 def dump ( buffer , opts \\ [ ] ) do
107+ timeout = Keyword . get ( opts , :timeout , 5000 )
108+
105109 with { :ok , { _ , parts } } <- fetch_buffer ( buffer ) ,
106110 { :ok , part } <- validate_partition ( opts , parts ) do
107111 case part do
108- :all -> { :ok , Enum . reduce ( 1 .. parts , [ ] , & ( & 2 ++ do_dump_part ( buffer , & 1 - 1 ) ) ) }
109- part -> { :ok , do_dump_part ( buffer , part ) }
112+ :all -> { :ok , Enum . reduce ( 1 .. parts , [ ] , & ( & 2 ++ do_dump_part ( buffer , & 1 - 1 , timeout ) ) ) }
113+ part -> { :ok , do_dump_part ( buffer , part , timeout ) }
110114 end
111115 end
112116 end
@@ -120,6 +124,8 @@ defmodule Buffer do
120124 * `:async` - Whether or not the flush will be async. Defaults to `true`.
121125
122126 * `:partition` - The specific partition to flush. Defaults to `:all`.
127+
128+ * `:timeout` - The timeout for the GenServer call in milliseconds. Defaults to `5000`.
123129 """
124130 @ spec flush ( GenServer . server ( ) , keyword ( ) ) :: :ok | { :error , atom ( ) }
125131 def flush ( buffer , opts \\ [ ] ) do
@@ -138,25 +144,33 @@ defmodule Buffer do
138144 ## Options
139145
140146 * `:partition` - The specific partition to return info for. Defaults to `:all`.
147+
148+ * `:timeout` - The timeout for the GenServer call in milliseconds. Defaults to `5000`.
141149 """
142150 @ spec info ( GenServer . server ( ) , keyword ( ) ) :: { :ok , list ( ) } | { :error , atom ( ) }
143151 def info ( buffer , opts \\ [ ] ) do
152+ timeout = Keyword . get ( opts , :timeout , 5000 )
153+
144154 with { :ok , { _ , parts } } <- fetch_buffer ( buffer ) ,
145155 { :ok , part } <- validate_partition ( opts , parts ) do
146156 case part do
147- :all -> { :ok , Enum . map ( 1 .. parts , & do_info_part ( buffer , & 1 - 1 ) ) }
148- part -> { :ok , [ do_info_part ( buffer , part ) ] }
157+ :all -> { :ok , Enum . map ( 1 .. parts , & do_info_part ( buffer , & 1 - 1 , timeout ) ) }
158+ part -> { :ok , [ do_info_part ( buffer , part , timeout ) ] }
149159 end
150160 end
151161 end
152162
153163 @ doc """
154164 Inserts the given item into the given `Buffer`.
165+
166+ ## Options
167+
168+ * `timeout` - The timeout for the GenServer call in milliseconds. Defaults to `5000`.
155169 """
156- @ spec insert ( GenServer . server ( ) , term ( ) ) :: :ok | { :error , atom ( ) }
157- def insert ( buffer , item ) do
170+ @ spec insert ( GenServer . server ( ) , term ( ) , timeout ( ) ) :: :ok | { :error , atom ( ) }
171+ def insert ( buffer , item , timeout \\ 5000 ) do
158172 with { :ok , { partitioner , _ } } <- fetch_buffer ( buffer ) do
159- do_insert ( buffer , partitioner , item )
173+ do_insert ( buffer , partitioner , item , timeout )
160174 end
161175 end
162176
@@ -169,6 +183,8 @@ defmodule Buffer do
169183 Defaults to `true`. If set to `false`, all items in the batch will be inserted
170184 regardless of flush conditions being met. Afterwards, if a limit has been exceeded,
171185 the buffer will be flushed async.
186+
187+ * `:timeout` - The timeout for the GenServer call in milliseconds. Defaults to `5000`.
172188 """
173189 @ spec insert_batch ( GenServer . server ( ) , Enumerable . t ( ) , keyword ( ) ) ::
174190 { :ok , non_neg_integer ( ) } | { :error , atom ( ) }
@@ -254,10 +270,10 @@ defmodule Buffer do
254270
255271 defp build_key ( buffer ) , do: { __MODULE__ , buffer }
256272
257- defp do_dump_part ( buffer , partition ) do
273+ defp do_dump_part ( buffer , partition , timeout ) do
258274 buffer
259275 |> buffer_partition_name ( partition )
260- |> Server . dump ( )
276+ |> Server . dump ( timeout )
261277 end
262278
263279 defp do_flush_part ( buffer , partition , opts ) do
@@ -266,16 +282,16 @@ defmodule Buffer do
266282 |> Server . flush ( opts )
267283 end
268284
269- defp do_info_part ( buffer , partition ) do
285+ defp do_info_part ( buffer , partition , timeout ) do
270286 buffer
271287 |> buffer_partition_name ( partition )
272- |> Server . info ( )
288+ |> Server . info ( timeout )
273289 end
274290
275- defp do_insert ( buffer , partitioner , item ) do
291+ defp do_insert ( buffer , partitioner , item , timeout ) do
276292 buffer
277293 |> buffer_partition_name ( partitioner . ( ) )
278- |> Server . insert ( item )
294+ |> Server . insert ( item , timeout )
279295 end
280296
281297 defp do_insert_batch ( buffer , partitioner , items , opts ) do
0 commit comments