I'm messing around with multithreaded coroutines i...
# multiplatform
b
I'm messing around with multithreaded coroutines in native but i cannot seem to get it to work. this is what i have
Copy code
fun calculateOnBackgroundThread() {
    viewModelScope.launch {
        val result = getFactorial()

        _factorialFlow.value = result.toString()
    }
}

private suspend fun getFactorial() = withContext(backgroundDispatcher) {
    calculateFactorial(5000)
}

private fun calculateFactorial(number: Int): BigInteger {
    var factorial = BigInteger.ONE
    for (i in 1..number) {
        factorial = factorial.multiply(BigInteger.fromLong(i.toLong()))
    }
    return factorial
}
but i get CoroutinesInternalError: Fatal exception in coroutines machinery for DispatchedContinuation What am I doing wrong?