Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Application.get_channel and Application.get_connection #212

Merged
merged 3 commits into from
Mar 1, 2022

Conversation

Zaherhs
Copy link
Contributor

@Zaherhs Zaherhs commented Feb 22, 2022

Application.get_channel and Application.get_connection no longer crash if the name of the process given is not alive.

Copy link
Collaborator

@ono ono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Only trivial comments. We can merge it once they are addressed. Thanks!

mix.exs Outdated
@@ -2,7 +2,7 @@ defmodule AMQP.Mixfile do
use Mix.Project

@source_url "https://github.com/pma/amqp"
@version "3.1.0"
@version "3.1.1"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the versioning bump from PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines 96 to 100
with false <- whereis(name) |> is_nil(),
conn <- GenServer.call(get_server_name(name), :get_connection) do
if conn |> is_nil(), do: {:error, :not_connected}, else: {:ok, conn}
else
true -> {:error, :connection_not_found}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with false <- whereis(name) |> is_nil(),
conn <- GenServer.call(get_server_name(name), :get_connection) do
if conn |> is_nil(), do: {:error, :not_connected}, else: {:ok, conn}
else
true -> {:error, :connection_not_found}
server_name = get_server_name(name)
with false <- server_name |> whereis() |> is_nil(),
conn = %{} <- GenServer.call(server_name, :get_connection)} do
{:ok, conn}
else
true -> {:error, :connection_not_found}
nil -> {:error, :not_connected}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whereis/1 function is already there in the module.:

  def whereis(name) do
    name
    |> get_server_name()
    |> GenServer.whereis()
  end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦

lib/amqp/application/channel.ex Show resolved Hide resolved
lib/amqp/application/channel.ex Show resolved Hide resolved
lib/amqp/application/channel.ex Show resolved Hide resolved
@ono ono mentioned this pull request Mar 1, 2022
@ono ono merged commit bd68c4d into pma:main Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants