Skip to content

Commit fc87ef5

Browse files
ochafikclaude
andcommitted
fix(kotlin-host): reduce teardown timeout from 3s to 500ms with polling
Changed from a fixed 3-second delay to polling every 50ms with a 500ms max timeout. This makes card dismissal feel much snappier while still giving apps time to respond to teardown requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 80cf7d9 commit fc87ef5

File tree

1 file changed

+7
-3
lines changed
  • examples/basic-host-kotlin/src/main/kotlin/com/example/mcpappshost

1 file changed

+7
-3
lines changed

examples/basic-host-kotlin/src/main/kotlin/com/example/mcpappshost/MainActivity.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,14 @@ fun McpAppWebView(
426426
val teardownMsg = """{"jsonrpc":"2.0","id":$requestId,"method":"ui/resource-teardown","params":{}}"""
427427
sendToWebView(teardownMsg)
428428

429-
// Timeout: if no response in 3 seconds, complete anyway
430-
kotlinx.coroutines.delay(3000)
429+
// Poll for completion with timeout (500ms total, checking every 50ms)
430+
var elapsed = 0
431+
while (!teardownCompleted && elapsed < 500) {
432+
kotlinx.coroutines.delay(50)
433+
elapsed += 50
434+
}
431435
if (!teardownCompleted) {
432-
android.util.Log.w("McpAppWebView", "Teardown timeout, completing anyway")
436+
android.util.Log.w("McpAppWebView", "Teardown timeout after ${elapsed}ms, completing anyway")
433437
teardownCompleted = true
434438
onTeardownComplete?.invoke()
435439
}

0 commit comments

Comments
 (0)