This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun rendezvousChannel( | |
coroutineScope: CoroutineScope | |
) { | |
// create a rendezvous channel with capacity 0 | |
val channel = Channel<Int>() | |
// get the starting time to display the time difference in the logs | |
val startTime = System.currentTimeMillis() | |
// launch the producer coroutine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
const val TAG = "Channel" | |
@OptIn(ExperimentalCoroutinesApi::class) | |
fun bufferedChannel( | |
coroutineScope: CoroutineScope | |
) { | |
// create a buffered channel with capacity of 2 | |
val channel = Channel<Int>(capacity = 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun LocationDisplay(activity: ComponentActivity) { | |
// Create a conflated channel for location updates | |
val locationChannel = remember { Channel<Location>(Channel.CONFLATED) } | |
// Create a mutable state for the location text | |
val locationState = remember { mutableStateOf("") } | |
// Receive location updates from the channel using a coroutine | |
LaunchedEffect(locationChannel) { | |
val scope = CoroutineScope(Dispatchers.Default) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.res.Configuration | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.Spacer | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.height | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.layout.size |