Refactor: replace songListScope with appropriate scopes

Replaced `songListScope` with `songScope` in `WSSongRoutes` and `timerScope` in `WSTimerRoutes` to better reflect their respective purposes. Improves code clarity and consistency in scope usage.
This commit is contained in:
dalbodeule 2025-04-24 17:48:11 +09:00
parent aa95976005
commit 61a5f985c1
No known key found for this signature in database
GPG Key ID: EFA860D069C9FA65
2 changed files with 10 additions and 10 deletions

View File

@ -26,7 +26,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
val songScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
fun Routing.wsSongRoutes() {
environment.monitor.subscribe(ApplicationStopped) {
songListScope.cancel()
songScope.cancel()
}
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
val status = ConcurrentHashMap<String, SongType>()
@ -77,7 +77,7 @@ fun Routing.wsSongRoutes() {
fun broadcastMessage(userId: String, message: SongResponse) {
val userSessions = sessions[userId]
userSessions?.forEach { session ->
songListScope.launch {
songScope.launch {
val success = sendWithRetry(session, message)
if (!success) {
logger.info("Removing session for user $userId due to repeated failures.")
@ -96,7 +96,7 @@ fun Routing.wsSongRoutes() {
}
addSession(uid, this)
if(status[uid] == SongType.STREAM_OFF) {
songListScope.launch {
songScope.launch {
sendSerialized(SongResponse(
SongType.STREAM_OFF.value,
uid,
@ -135,7 +135,7 @@ fun Routing.wsSongRoutes() {
dispatcher.subscribe(SongEvent::class) {
logger.debug("SongEvent: {} / {} {}", it.uid, it.type, it.current?.name)
songListScope.launch {
songScope.launch {
broadcastMessage(it.uid, SongResponse(
it.type.value,
it.uid,
@ -148,7 +148,7 @@ fun Routing.wsSongRoutes() {
}
dispatcher.subscribe(TimerEvent::class) {
if(it.type == TimerType.STREAM_OFF) {
songListScope.launch {
songScope.launch {
broadcastMessage(it.uid, SongResponse(
it.type.value,
it.uid,

View File

@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
val timerScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
fun Routing.wsTimerRoutes() {
environment.monitor.subscribe(ApplicationStopped) {
songListScope.cancel()
timerScope.cancel()
}
val sessions = ConcurrentHashMap<String, ConcurrentLinkedQueue<WebSocketServerSession>>()
val logger = LoggerFactory.getLogger("WSTimerRoutes")
@ -77,7 +77,7 @@ fun Routing.wsTimerRoutes() {
fun broadcastMessage(uid: String, message: TimerResponse) {
val userSessions = sessions[uid]
userSessions?.forEach { session ->
songListScope.launch {
timerScope.launch {
val success = sendWithRetry(session, message.copy(uid = uid))
if (!success) {
logger.info("Removing session for user $uid due to repeated failures.")
@ -98,11 +98,11 @@ fun Routing.wsTimerRoutes() {
val timer = CurrentTimer.getTimer(user)
if (timer?.type == TimerType.STREAM_OFF) {
songListScope.launch {
timerScope.launch {
sendSerialized(TimerResponse(TimerType.STREAM_OFF.value, null, uid))
}
} else {
songListScope.launch {
timerScope.launch {
if(timer?.type == TimerType.STREAM_OFF) {
sendSerialized(TimerResponse(TimerType.STREAM_OFF.value, null, uid))
} else {
@ -157,7 +157,7 @@ fun Routing.wsTimerRoutes() {
logger.debug("TimerEvent: {} / {}", it.uid, it.type)
val user = UserService.getUser(it.uid)
CurrentTimer.setTimer(user!!, it)
songListScope.launch {
timerScope.launch {
broadcastMessage(it.uid, TimerResponse(it.type.value, it.time ?: "", it.uid))
}
}