Created
December 18, 2017 21:04
-
-
Save zorbash/0145626da5cf177cbb4409107e4db760 to your computer and use it in GitHub Desktop.
Happy Place - 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Example | |
@pubsub ExampleApp.PubSub | |
@spec websocket_connections([non_neg_integer]) :: non_neg_integer | |
def websocket_connections([_ | _] = shards) do | |
shards | |
|> Enum.map(&Phoenix.PubSub.Local.local_name(@pubsub, &1)) | |
|> Enum.reduce(0, fn name, acc -> | |
with pid when is_pid(pid) <- Process.whereis(name), | |
info when is_list(info) <- Process.info(pid, [:monitors])[:monitors], | |
procs when is_list(procs) <- info |> Enum.map(&(elem(&1, 1))) do | |
acc + length(procs) | |
else | |
_ -> acc | |
end | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment