I want to run a function in a background thread with Dispatcher.IO on recycleView code like this
class FileAdapter(val isFromNetwork : Boolean, val context: Context, val tools: Tools, val coroutineScope: CoroutineScope):RecyclerView.Adapter<FileAdapter.FileHolder>() {
...
override fun onBindViewHolder(holder: FileHolder, position: Int) {
coroutineScope.launch{
val task =async(Dispatchers.IO){ tools.networkFileManager(networkFileList[position]) }
task.await().let{
//some view function
}
}
...
}
with code like that the tools.networkFileManager function runs in the background thread at the same time. how to get tools.networkFileManager called in the background thread sequentially? (next thread waiting for the previous thread to finish)