Skip to content

make DeviceService.getDeviceScreen suspend#3178

Open
proksh wants to merge 1 commit intomainfrom
fix/studio-suspend-getdevicescreen
Open

make DeviceService.getDeviceScreen suspend#3178
proksh wants to merge 1 commit intomainfrom
fix/studio-suspend-getdevicescreen

Conversation

@proksh
Copy link
Copy Markdown
Contributor

@proksh proksh commented Apr 14, 2026

Summary

  • getDeviceScreen and takeScreenshot are now suspend functions, removing runBlocking wrappers around viewHierarchy(), deviceInfo(), and takeScreenshot() calls
  • Replaces synchronized(DeviceService) with coroutine Mutex - synchronized can't be used with suspend functions since it locks a thread, but a suspend function may resume on a different thread. Mutex provides the same mutual exclusion but suspends the coroutine instead of blocking the thread.

Why

getDeviceScreen is called from the /api/device-screen/sse endpoint inside respondBytesWriter, which is already a suspend context. Using runBlocking here blocks a Ktor dispatcher thread for the duration of each device call. Under concurrent SSE connections, this ties up threads unnecessarily. Since all the underlying Maestro methods are already suspend (from #3162), we can just call them directly.

…r dispatcher

Replace runBlocking with direct suspend calls in getDeviceScreen and
takeScreenshot. Use Mutex instead of synchronized to support suspension
within the critical section. This avoids tying up Ktor dispatcher
threads on the SSE hot path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants