Skip to content

Commit

Permalink
Fix data race
Browse files Browse the repository at this point in the history
  • Loading branch information
SerVB committed Feb 6, 2020
1 parent fd5f44d commit 7bd0884
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class ChatServer(port: Int) : WebSocketServer(InetSocketAddress(port)) {
private var nextId = 0

override fun onOpen(connection: WebSocket, handshake: ClientHandshake?) {
val id = ++nextId
val id = synchronized(this) {
++nextId
}

val message = "#$id connected"
sendToAll(message)
Expand Down

0 comments on commit 7bd0884

Please sign in to comment.