Kotlin等到函数结束

我正在做一个http请求,但如果我得到答案,我需要返回一个值。 我的问题是,我的代码继续,我的http请求还没有完成。 但我总是得到错误,因为函数返回前请求结束我正在使用燃料库

感谢这样的事情:

fun get_data():Boolean{ val URL:String="http:myurl" var response:Boolean=false URL.httpGet( listOf("user" to "user")).responseJson{request, response, result -> result.fold( success = { json -> response=true }, failure = { error -> response=false } ) } return response } 

问题是,你正在使用燃料库的异步模式 ,你应该使用的是阻塞模式 。

像这样的东西

 val (request, response, result) = URL.httpGet().responseJson()