Unresolved reference async in Kotlin

后端 未结 3 2013
情歌与酒
情歌与酒 2021-01-04 03:22

I am trying to perform network operation async in Kotlin. I read it you can do async using async function. I am getting below error, can anyone gue

3条回答
  •  萌比男神i
    2021-01-04 03:56

    async is available inside kotlinx.couroutines

    Make sure that you added the dependency in your gradle file:

    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
    

    Also make sure that the async is called on a coroutine scrope such as GlobalScope.

     val deferredResult = GlobalScope.async {
    
                }
    

提交回复
热议问题