BuddyGG / buddy_matching

Somewhat generic player matching service built with Elixir and Phoenix
https://www.buddy.gg
GNU Affero General Public License v3.0
64 stars 7 forks source link

Convert LeaveTracker to singleton GenServer #117

Closed ecly closed 6 years ago

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 189


Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/buddy_matching_web/lib/buddy_matching_web/presence/leave_tracker.ex 1 2 50.0%
apps/buddy_matching_web/lib/buddy_matching_web/presence/supervisor.ex 0 1 0.0%
<!-- Total: 2 4 50.0% -->
Totals Coverage Status
Change from base Build 185: -0.03%
Covered Lines: 325
Relevant Lines: 360

💛 - Coveralls
Hanspagh commented 6 years ago

Looks good, out of curiosity is a pattern to use singleton gen servers, or where do you see the benefit?

ecly commented 6 years ago

@Hanspagh Should indeed be a pattern. To avoid having to do :global.whereis_name/1, when wanting to a call a GenServer that we know will be only be created one instance of ever. Makes the interface much easier to work with.

They for example present it in the 'Programming Elixir` book:

As we left it, our server works but is ugly to use. Our callers have to make explicit GenServer calls, and they have to know the registered name for our server process. We can do better... ... This is the pattern you should use in your servers.