Mark
01/09/2023, 10:02 AM<http://java.io|java.io>
should be called using <http://Dispatchers.IO|Dispatchers.IO>
dispatcher? For example File.exists
File.canRead
etclouiscad
01/09/2023, 6:39 PMyschimke
01/09/2023, 9:51 PMyschimke
01/09/2023, 9:53 PMlouiscad
01/09/2023, 10:02 PMMark
01/10/2023, 2:05 AMsuspend fun someFun() {
someSuspendingFun() // suppose I know that this uses <http://Dispatchers.IO|Dispatchers.IO>
if (someFile.exists()) {
...
}
}
and I realise that File.exists
might touch the file system. Should I solve this by:
suspend fun someFun() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
someSuspendingFun()
if (someFile.exists()) {
...
}
}
or:
suspend fun someFun() {
someSuspendingFun()
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
if (someFile.exists()) {
...
}
}
}
yschimke
01/10/2023, 3:13 AM