Skip to content

New callback for generic message handling #48

@oliveigah

Description

@oliveigah

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:

  1. Adding a handle_info/2 clause to NimblePool that matches messages like {:pool_info, term}.

  2. Adding pool_send/2 and pool_send_after/2 functions to send a term to the pool, wrapping it in the :pool_info tuple.

  3. The new handle_info/2 would unwrap and forward the term to a user-defined handle_pool_info/2 callback, which would receive the term and the pool state.

  4. The handle_pool_info/2 may return the same options as the GenServer's handle_info callback and it will in fact be the return value of the new handle_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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions