@angelthorns Basically the pattern I came up with is:
1) Create Vec that will store client mpsc channels (which are thankfully Clone) and messages you want to send them
2) Lock state structure (I used an RwLock because for the most common case, PRIVMSG and NOTICE, you don't need to mutate much client state)
3) Perform CRUD-style updates to the users
4) Enqueue messages to send to the users as well as their queues
5) Drop the lock
6) Process all the messages in the Vec you just created
It is... actually much more messy and heavy than the same C/C++ code, and not a super scalable design. But the architecture of a chat system makes it virtually unavoidable unless you store thousands of per-user locks... which is not great overhead either and requires locking/unlocking potentially thousands of locks per operation too.
I mean, hey, if anyone else has better ideas I'm open to it, but this seems to be the way everyone suggests doing it.
@natty @angelthorns Yeah, the problem is IRC's state machine is enormous. Clients alone have 20+ pieces of state (nick, ident/username, host, real name, mpsc queue, modeset, target change, token bucket, last ping received, pending ping, away message if any, channel membership list (needed for WHOIS), MONITOR list, capabilities list, quit flag and message (if the user is leaving, you need to broadcast it and send an ERROR to the client before disconnecting them)... things like nick, ident/username, host, mpsc queue, modeset, capabilities, etc. all affect how a message is set, what kind of message is sent (with or without tags, etc.), what is sent with it (nick/user/host is included in most messages from a user), etc.
Much of this state doesn't change often, but other state is pretty changeable (like nickname or away message or channel membership), sometimes by the user, sometimes by other users (think /SANICK etc.) so it is extremely painful to deal with it.