我想从协程内部的外部函数返回。以下是我的(失败)尝试。当我尝试返回时,出现编译时错误
此处不允许“返回”
有人知道解决方法吗?还是不可能?
fun main() {
run func@ {
GlobalScope.launch {
withContext(Dispatchers.IO) {
return@func // 'return' is not allowed here
}
}
println("This line should not be executed")
}
}