generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(streaming): enhance OnStreamingService with registration and not…
…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
Showing
1 changed file
with
30 additions
and
1 deletion.
There are no files selected for viewing
31 changes: 30 additions & 1 deletion
31
shirelang/src/main/kotlin/com/phodal/shirelang/run/streaming/OnStreamingService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |