Skip to content

Commit 36c2f60

Browse files
refactor: TextWebSocketFrame creations (#1)
1 parent 9d8f65f commit 36c2f60

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/kotlin/net/ccbluex/netty/http/websocket/WebSocketController.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,19 @@ class WebSocketController {
3737
/**
3838
* Broadcasts a message to all connected clients.
3939
*
40-
* @param message The message to broadcast.
40+
* @param text The message to broadcast.
4141
* @param failure The action to take if a failure occurs.
4242
*/
4343
fun broadcast(text: String, failure: (ChannelHandlerContext, Throwable) -> Unit = { _, _ -> }) {
44+
val frame = TextWebSocketFrame(text)
4445
activeContexts.forEach { handlerContext ->
4546
try {
46-
handlerContext.channel().writeAndFlush(TextWebSocketFrame(text))
47+
handlerContext.channel().writeAndFlush(frame.retain())
4748
} catch (e: Throwable) {
4849
failure(handlerContext, e)
4950
}
5051
}
52+
frame.release()
5153
}
5254

5355
/**
@@ -79,4 +81,4 @@ class WebSocketController {
7981
activeContexts.remove(context)
8082
}
8183

82-
}
84+
}

0 commit comments

Comments
 (0)