Skip to content

Commit

Permalink
Wait for client ready on loading commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Sep 19, 2024
1 parent c564f7d commit 9948ca4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package ai.devchat.core.handlers

import ai.devchat.core.BaseActionHandler
import ai.devchat.core.DevChatActions
import ai.devchat.core.DevChatClient
import com.alibaba.fastjson.JSONObject
import com.intellij.openapi.project.Project
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeoutOrNull


class ListCommandsRequestHandler(project: Project, requestAction: String, metadata: JSONObject?, payload: JSONObject?) : BaseActionHandler(
Expand All @@ -14,6 +18,15 @@ class ListCommandsRequestHandler(project: Project, requestAction: String, metada
) {
override val actionName: String = DevChatActions.LIST_COMMANDS_RESPONSE
override fun action() {
var client: DevChatClient? = null
runBlocking {
client = withTimeoutOrNull(5000) { // 5000 milliseconds = 5 seconds timeout
while (devChatService.client == null) {
delay(100) // Wait for 100 milliseconds before checking again
}
devChatService.client
}
}
val recommendedWorkflows = client?.getWorkflowConfig()?.recommend?.workflows.orEmpty()
val indexedCommands = client?.getWorkflowList()?.map {
val commandName = it.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ class DevChatToolWindowFactory : ToolWindowFactory, DumbAware, Disposable {
devChatService.activeConversation = ActiveConversation()
}

override fun dispose() {
// TODO("Not yet implemented")
}
override fun dispose() {}
}

0 comments on commit 9948ca4

Please sign in to comment.