-
Notifications
You must be signed in to change notification settings - Fork 41
TileCollector design
The core design of MapView
is the TileCollector
. This is the component responsible for asynchronously loading tiles. It uses Kotlin coroutines, Channels
and Flow
. It's an implementation of Hoare’s CSP (Communicating Sequential Processes) model.
This is the architecture:
TileCollector
interacts with the view-model with two channels:
- one to receive
TileStatus
s (a [ReceiveChannel]) - one to send
Tile
s (a [SendChannel])
Internally, the "Collector kernel" process incoming TileStatus
objects and check whether or not the same request was made recently and is currently in progress. To ensure an overall good performance, this architecture supports back-pressure. So, when the collector is overwhelmed, it cannot processes more tiles and the coroutine that submits TileSpec
s in the receive channel gets suspended. It avoids the situation where too much work is submitted to the collector, that further requires a cancellation mechanism.
It also receives TileStatus
from the workers, which send back those objects when a tile was successfully fetched.