I am new to kotlin coroutine, i am using Channel in my coroutine, I need to know whether the channel created in the particular scope will get cancelled once the scope get cancelled.
will the channels acts as a children in that scope?
Example
class TestingChannel {
val channel = Channel<String>(Channel.BUFFERED)
suspend fun start() {
coroutineScope {
awaitAll(
async { startSendingData() },
async { startReceiveData() }
)
}
}
suspend fun startSendingData() {
channel.send("some_data")
}
suspend fun startReceiveData() {
for (data in channel) {
print(data)
}
}
}
class ViewModel : ViewModel() {
init {
viewModelScope.launch {
TestingChannel().start()
}
}
override fun onCleared() {
super.onCleared()
/**
* on Clearing the viewmodel scope, will my channel in the that scope stop sending or receiving data
*/
}
}
In the above code i don't use produce function since it is in experimental state.
Can anyone help me with this?