I am trying to run the following code but it's not running because the compiler doesn't know which version of the async method to call. How do I tell it which one to call?
v
ar counter=0
val workerA=asyncIncrement(5000)
val workerB=asyncIncrement(100)
workerA.await()
workerB.await()
print("counter = $counter")
fun asyncIncrement(by:Int)=async{
    for(i in 1..by){
        counter++
    }
}
Just copy and paste the code into a scratch file or wherever and you should see the same compiler error
                        
From Kotlin 1.3 you need to call
asyncon a scope. In this example I have chosen theGlobalScope. But it doesn't matter which scope you choose, you always have to explicitly import theasyncextension function;BTW: I changed the variable
counterfromintto anAtomicIntegerbecause the twoasyncblocks may run in different threads. And I introducedrunBlocking, becauseawaithas to run in a suspend function.