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:
user to subscribe to an external topic
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.
2 Likes
Aha, now I understand the reason. Thank you for the reply! = )
1 Like
idi527
April 27, 2017, 9:36pm
4
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
.
2 Likes
idi527:
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.
2 Likes