Join vs after_join

Just got a question while implementing Phoenix channel.

What kind of functions should be put in “join” and what kind of functions should be executed in “handle_info(:after_join…)” ?

For example I have actions to take when user join:

  1. user to subscribe to an external topic
  2. Presence.track user

Should I put all of those to handle_info(:after_join…) ?
Thank you = )

Put in anything in :after_join that requires the socket since the socket is not ‘set up’ until after join returns. :slight_smile:


Aha, now I understand the reason. Thank you for the reply! = )

1 Like

Also I think join in phoenix channels is somewhat similar to init in a genserver. So the same rules apply, you would not want to put something slow in init or join, but instead handle it later with handle_info. Since neither of your actions are particularly slow, I don’t see anything wrong with putting them in join.


Except you cannot broadcast the startup presence data from it since the topic is not fully up yet too, needs to be in after_join.