elixir-ecto / db_connection

Database connection behaviour
http://hexdocs.pm/db_connection/DBConnection.html
306 stars 113 forks source link

Should `notify_connection_listeners` just be `telemetry` events? #261

Closed isaacsanders closed 2 years ago

isaacsanders commented 2 years ago

Right now there is system that couples the disconnects and connects to the specific implementation of connection listeners, but I think that the current approach for this soft of "observer" pattern would be more often done as a telemetry event.

josevalim commented 2 years ago

The main reason is that we don't want to allow custom code to run from connection processes, so a subscription style seems more appropriate. You can always emit telemetry from a listener though!

Also note that disconnected is not guaranteed to be invoked, I pushed some docs making it clearer. So you need a subscription+monitor depending on what you want to achieve with telemetry.