@@ -42,7 +42,7 @@ interacting with pools.
4242
4343[source,erlang]
4444----
45- worker_ref () = term()
45+ ref () = term()
4646
4747pool() = atom()
4848
@@ -56,23 +56,25 @@ strategy() = fifo | lifo
5656
5757linger() = infinity | {MaxLinger :: non_neg_integer(), Interval :: non_neg_integer()}
5858
59+ restart() = never | out | always.
60+
5961on_return() = undefined | {fun((worker()) -> any()), timeout()}
6062
6163shutdown() = timeout() | brutal_kill
6264
63- worker_status() = idle | out | returning
65+ worker_status() = starting | idle | out | returning | restarting
6466
6567pool_status() = #{
66- idle := non_neg_integer(),
67- out := non_neg_integer(),
68- starting := non_neg_integer(),
69- returning := non_neg_integer()
68+ available := non_neg_integer(),
69+ unavailable := non_neg_integer(),
70+ starting := non_neg_integer()
7071}
7172
7273opts() = #{
7374 size => size(),
7475 strategy => strategy(),
7576 linger => linger(),
77+ restart => restart(),
7678 on_return => on_return(),
7779 shutdown => shutdown()
7880}
@@ -145,6 +147,20 @@ specified by the `size` option.
145147If set to `infinity` instead, workers never expire, and the pool may
146148eventually grow to the maximum number defined by the `size` option.
147149
150+ restart (never)::
151+
152+ Worker restart strategy of the pool.
153+
154+ If set to `never`, failing workers will not be restarted by their
155+ agents, and the agents themselves will fail.
156+
157+ If set to `out`, failing workers will be restarted by their agents
158+ if they are checked out, but not if they are idle, in which case
159+ the agents themselves will fail.
160+
161+ If set to `always`, failing workers will be transparently restarted
162+ by their agents, no matter if they are checked out or idle.
163+
148164on_return (undefined)::
149165
150166Function to be called when a worker returns to the pool.
@@ -230,7 +246,7 @@ WorkerRef = hnc:checkout(PoolName, Timeout).
230246
231247PoolName = pool():: Pool identifier as given in `start_pool/4`.
232248Timeout = timeout():: Maximum time to wait for the checkout to succeed.
233- WorkerRef = worker_ref ():: The identifier of the worker that was checked out from the pool.
249+ WorkerRef = ref ():: The identifier of the worker that was checked out from the pool.
234250
235251Checks out a worker from the pool. If the pool has `idle` workers available,
236252it will return one of them. Which of the available workers is picked depends
@@ -250,14 +266,12 @@ worker.
250266
251267[source,erlang]
252268----
253- Result = hnc:checkin(WorkerRef).
254- Result = hnc:checkin(WorkerRef, Timeout).
269+ ok = hnc:checkin(WorkerRef).
270+ ok = hnc:checkin(WorkerRef, Timeout).
255271----
256272
257273WorkerRef = worker_ref():: The identifier of the worker to be checkedi back in, as returned by `checkout/1,2`.
258274Timeout = timeout():: Maximum time to wait for the checkin to succeed.
259- Result = ok | {error, Reason}:: The result of the `checkin` operation.
260- Reason = not_owner | not_found:: If checking in failed, the reason for the failure.
261275
262276Returns the worker identified by the given `WorkerRef` to the pool.
263277
@@ -269,7 +283,7 @@ it in the `on_return` option, the worker is killed and removed from the pool, as
269283it is then assumed to be in an undefined state.
270284
271285Returns `ok` on success. If the process doing the checkin is not the current owner
272- of the worker, `{ error, not_owner} ` is returned .
286+ of the worker identifier, an error exception with reason ` not_owner` is raised .
273287
274288=== Performing a transaction
275289
@@ -298,22 +312,20 @@ If you want the worker to remain checked out, you may give it away to another pr
298312
299313[source,erlang]
300314----
301- Result = hnc:give_away(WorkerRef, NewUser, GiftData).
302- Result = hnc:give_away(WorkerRef, NewUser, GiftData, Timeout).
315+ ok = hnc:give_away(WorkerRef, NewUser, GiftData).
316+ ok = hnc:give_away(WorkerRef, NewUser, GiftData, Timeout).
303317----
304318
305- WorkerRef = worker_ref ():: The identifier of the worker to be transferred to `NewUser`, as returned by `checkout/1,2`.
319+ WorkerRef = ref ():: The identifier of the worker to be transferred to `NewUser`, as returned by `checkout/1,2`.
306320NewUser = pid():: The pid of the process to give the worker to.
307321GiftData = term():: Additional data to send to the new user.
308322Timeout = timeout():: Maximum time to wait before a worker becomes available.
309- Result = ok | {error, Reason}:: The result of the `give_away` operation.
310- Reason = not_owner | not_found:: If giving away failed, the reason for the failure.
311323
312324On success, `ok` is returned. Additionally, the new owner process is sent a message
313325`{'HNC-WORKER-TRANSFER', WorkerRef, FromPid, GiftData}`.
314326
315- If the process calling this function is not the owner of the worker, `{ error, not_owner}`
316- is returned .
327+ If the process calling this function is not the owner of the worker identifier, an error exception
328+ with reason `not_owner` is raised .
317329
318330=== Getting and setting the checkout strategy
319331
@@ -384,9 +396,9 @@ Status = hnc:worker_status(WorkerRef).
384396Status = hnc:worker_status(WorkerRef, Timeout).
385397----
386398
387- WorkerRef = worker_ref ():: The identifier of the worker whose status to query.
399+ WorkerRef = ref ():: The identifier of the worker whose status to query.
388400Timeout = timeout():: Maximum time to wait.
389- Status = worker_status() | undefined :: The status of the given worker of the given pool.
401+ Status = worker_status():: The status of the given worker of the given pool.
390402
391403Retrieve the status of the given worker.
392404
@@ -408,7 +420,6 @@ Status = pool_status():: The status of the given pool.
408420
409421Retrieve the pool status in a map.
410422
411- * `idle `: number of checked in ( available) workers.
412- * `out `: number of checked out (not available) workers.
423+ * `available `: number of available workers.
424+ * `unavailable `: number of unavailable workers.
413425* `starting`: number of workers that are in the process of being started (not yet available).
414- * `returning`: number of workers that are in the process of returning (not yet available).
0 commit comments