【发布时间】:2017-11-03 11:16:08
【问题描述】:
我在 Kotlin(Android 应用)中有这个功能:
tailrec fun factorial(n: BigInteger, remainder: BigInteger = BigInteger.ONE) : BigInteger{
if(n== BigInteger.ZERO)
return remainder
else {
return factorial(n - BigInteger.ONE, remainder * n)
}
}
还有这个简单的代码:
button.setOnClickListener {
val n = editTextT.text.toString()
val result: BigInteger = factorial(BigInteger(n))
textView.text = "$n! is $result"
}
我的问题是:有没有办法以异步方式进行这种计算?如果是,怎么做?
【问题讨论】:
-
您希望
factorial的每个递归调用异步运行(用于实验),还是只在 UI 线程外的协程中运行整个计算? -
脱离 UI 线程
标签: android asynchronous kotlin