Complete rewrite
This commit is contained in:
@@ -29,7 +29,7 @@ func NewServer(address string) (*Server, error) {
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
connectedClients: newConnectedClients(),
|
||||
incomingMessages: make(chan IncomingMessage),
|
||||
incomingMessages: make(chan IncomingMessage, 1024),
|
||||
}
|
||||
|
||||
go (func() {
|
||||
@@ -55,7 +55,7 @@ func (server *Server) handleConnection(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
clientCtx, cancel := context.WithCancelCause(server.ctx)
|
||||
outgoingMessages := make(chan OutgoingMessage)
|
||||
outgoingMessages := make(chan OutgoingMessage, 1024)
|
||||
|
||||
clientId := server.connectedClients.Enroll(func(id ClientId) ConnectedClient {
|
||||
return ConnectedClient{
|
||||
@@ -141,7 +141,9 @@ func (server *Server) SendMessage(client ClientId, content Content) {
|
||||
Content: content,
|
||||
}
|
||||
server.connectedClients.BorrowIfPresent(client, func(connectedClient *ConnectedClient) {
|
||||
log.Printf("putting in outgoing")
|
||||
connectedClient.outgoingMessages <- outgoing
|
||||
log.Printf("done putting in outgoing")
|
||||
})
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user