Yonto Player plays your own library, and you can add several sources to it: a Jellyfin server, a Plex server, a folder on a NAS. Most screens show…
Yonto Player plays your own library, and you can add several sources to it: a Jellyfin server, a Plex server, a folder on a NAS. Most screens show one source at a time, the active one. Search is the one place that asks all of them at once. That sounds like a loop over a list. In practice a TV app has a few constraints that make the loop interesting: a remote for typing, and sources that answer at very different speeds.
This post is about the choices that keep Search fast and honest, and about the Watch list that grew out of it. Search stays live The obvious way to search many sources is to build an index of all of them in the background and query that. I chose not to. An index needs a walker that keeps every source in step, and I did not want that running on a television. So Search asks the sources when you type, only more of them.
The cost is that each search goes out to the sources again. Which sources get asked is a small filter: the source is on; its config can search at all (a catalog saved as not searchable is left out); its last health check does not say it needs you, for example a login or a fixed address. The active source is asked whatever its last check said.
Fan out, collect as they arrive The core of it is a small class that takes a list of sources and an ask function. It starts one coroutine per source, lets at most three run at the same time, and hands every answer to the screen the moment it lands.
Here is a simplified sketch, with generic names, of how it is shaped: concurrency: Int, ask: suspend (Source) -> Outcome, onAnswer: (outcomes: Map, pending: Int) -> Unit, ) = coroutineScope { val permits = Semaphore(concurrency) val finished = Channel(Channel.UNLIMITED) val outcomes = LinkedHashMap() repeat(sources.size) { // collect as they arrive val (source, outcome) = finished.receive() outcomes[source] = outcome onAnswer(outcomes, sources.size - it - 1) // merge and show now } Two details matter more than they look. The first is the finally.
This is a source-linked briefing. Read the original report from Dev Community .