https://kotlinlang.org logo
Title
y

Yogeshvu

04/27/2023, 2:34 PM
I am trying to download files from multiple repositories by calling a suspend function(downloadFile). I provide a mapOf(repo, index) and call the downloadFile inside an async. How to ensure that downloadFile is threadsafe?
b

bezrukov

04/27/2023, 5:42 PM
it depends on which dispatcher you run this code. If it is multithreaded dispatcher (Default/IO, etc), downloadFile will be called concurrently. If you don't want this, just don't use async/await, and map them sequentially. Worths noting, concurrent access to downloadFile is not necessarily bad - we don't see the code inside, it might be perfectly fine.
y

Yogeshvu

04/27/2023, 6:25 PM
thanks