Skip to content

Commit 97df266

Browse files
committed
Remove unused closingService flag
1 parent b1570ce commit 97df266

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/FeatureNotificationService.kt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,14 @@ internal class FeatureNotificationService(
208208
/** Coroutine scope used to handle asynchronous notifications. */
209209
private val notificationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
210210

211-
/** Flag indicating whether the service is closing. */
212-
private val closingService = atomic(false)
213-
214211
/** Shared flow used to emit events within the feature notification service. */
215212
private val notificationEvents = MutableSharedFlow<NotificationEvent>(
216213
extraBufferCapacity = notificationBufferCapacity,
217214
onBufferOverflow = BufferOverflow.SUSPEND,
218215
)
219216

220217
/** Active emit jobs. */
221-
private val activeEmitJobs = atomic(persistentSetOf<Job>())
218+
private val emitJobs = atomic(persistentSetOf<Job>())
222219

223220
/** Notification jobs associated with sessions. */
224221
private val sessionNotificationJobs = atomic(persistentMapOf<ServerSessionKey, SessionNotificationJob>())
@@ -259,10 +256,6 @@ internal class FeatureNotificationService(
259256
logger.info { "Subscribing session for notifications sessionId: ${session.sessionId}" }
260257

261258
val timestamp = getCurrentTimestamp()
262-
if (closingService.value) {
263-
logger.debug { "Skipping subscription notification as service is closing: ${session.sessionId}" }
264-
return
265-
}
266259

267260
sessionNotificationJobs.getAndUpdate {
268261
if (it.containsKey(session.sessionId)) {
@@ -333,10 +326,6 @@ internal class FeatureNotificationService(
333326
private fun emit(notification: Notification) {
334327
// Create a timestamp before emit to ensure notifications are processed in order
335328
val timestamp = getCurrentTimestamp()
336-
if (closingService.value) {
337-
logger.debug { "Skipping emitting notification as service is closing: $notification" }
338-
return
339-
}
340329

341330
logger.info { "Emitting notification $timestamp: $notification" }
342331

@@ -348,11 +337,11 @@ internal class FeatureNotificationService(
348337
}
349338

350339
// Add job to set before starting
351-
activeEmitJobs.getAndUpdate { it.add(job) }
340+
emitJobs.getAndUpdate { it.add(job) }
352341

353342
// Register completion
354343
job.invokeOnCompletion {
355-
activeEmitJobs.getAndUpdate { it.remove(job) }
344+
emitJobs.getAndUpdate { it.remove(job) }
356345
}
357346

358347
// Start the job after it's safely added
@@ -365,10 +354,9 @@ internal class FeatureNotificationService(
365354

366355
suspend fun close() {
367356
logger.info { "Closing feature notification service" }
368-
closingService.compareAndSet(false, update = true)
369357

370358
// Making sure all emitting jobs are completed
371-
activeEmitJobs.value.joinAll()
359+
emitJobs.value.joinAll()
372360

373361
// Emitting end event to complete all session notification jobs
374362
notificationScope.launch {

0 commit comments

Comments
 (0)