A walkthrough of Kotlin's select expressions through an evolving real-world example: parallel token fetching that grows to include timeouts and fallback logic. The post demonstrates how the same set of Deferred sources can be reused across two distinct strategies — collecting all results within a time budget, then falling back to awaiting the first non-null result — by changing only the handling after each select clause. Key properties of select are explained: single-coroutine sequential execution, deregistration vs. cancellation of losing sources, and clause flexibility across Deferred, Channel, and Job types. The experimental status of select's API surface is also clarified.

10m read timeFrom proandroiddev.com
Post cover image
Table of contents
The core ideaCollecting what arrives in timeWhy a loop, not a single selectGet Daniil Chernyaev’s stories in your inboxWhen nothing makes it in timeWhat select properties mean for tool choiceA note on experimental statusWrapping up
257 Impressions