Skip to content

Commit

Permalink
feat(streaming): enhance OnStreamingService with registration and not…
Browse files Browse the repository at this point in the history
…ification #160

- Refactor `map` to store `LifecycleProcessorSignature` and `StreamingServiceProvider`.
- Add methods for registering, unregistering, and listing streaming services.
- Implement notification and completion handlers for all registered services.
  • Loading branch information
phodal committed Dec 17, 2024
1 parent 8997e96 commit b7cc22e
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
package com.phodal.shirelang.run.streaming

import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.phodal.shirecore.middleware.post.LifecycleProcessorSignature
import com.phodal.shirecore.provider.streaming.StreamingServiceProvider
import kotlinx.coroutines.flow.Flow

/**
* Manage all [com.phodal.shirecore.provider.streaming.StreamingServiceProvider]
*/
@Service(Service.Level.APP)
class OnStreamingService {
val map = mutableMapOf<String, LifecycleProcessorSignature>()
val map = mutableMapOf<LifecycleProcessorSignature, StreamingServiceProvider>()

fun registerStreamingService(sign: LifecycleProcessorSignature) {
val streamingService = StreamingServiceProvider.getStreamingService(sign.funcName)
if (streamingService != null) {
map[sign] = streamingService
}
}

fun unregisterStreamingService(sign: LifecycleProcessorSignature) {
map.remove(sign)
}

fun all(): List<StreamingServiceProvider> {
return map.values.toList()
}

fun notifyAll(project: Project, flow: Flow<String>, args: Map<String, Any>) {
map.forEach { (sign, service) ->
service.onStreaming(project, flow, args)
}
}

fun onDone(project: Project) {
map.forEach { (_, service) ->
service.onDone(project)
}
}
}

0 comments on commit b7cc22e

Please sign in to comment.