-
Notifications
You must be signed in to change notification settings - Fork 24
Description
As discussed in #46, introducing a new callback for generic message handling inside the pool process could be very useful!
It would enable at least two features:
-
Idle termination of empty pools (currently not possible with
handle_ping/2, as it only pings workers). -
Safe pool termination, avoiding race conditions when a checkout occurs just as the pool is about to terminate due to idleness.
From what I understand of the proposed solution, it would involve:
-
Adding a
handle_info/2clause to NimblePool that matches messages like{:pool_info, term}. -
Adding
pool_send/2andpool_send_after/2functions to send a term to the pool, wrapping it in the:pool_infotuple. -
The new
handle_info/2would unwrap and forward the term to a user-definedhandle_pool_info/2callback, which would receive the term and the pool state. -
The
handle_pool_info/2may return the same options as the GenServer'shandle_infocallback and it will in fact be the return value of the newhandle_info/2
I think this approach is as flexible as we could get and may enable the user side implementation of pretty much everything.
If you're on board with this idea and implementation, I can probably start working on it by the weekend.
Let me know your thoughts! Thanks!