Is this correct way of doing `parMapN`? ``` interf...
# arrow
s
Is this correct way of doing
parMapN
?
Copy code
interface SomeRepo {

    suspend fun getId(someId: Int): Either<Throwable, Int>
    suspend fun getName(someName: String): Either<Throwable, String>
}

interface AnotherClass {

    val someRepo: SomeRepo

    suspend fun <A, B> getResult(someName: String, someId: Int): Either<Throwable, Tuple2<Int, String>> {
        return parMapN(
            suspend { someRepo.getId(someId) },
            suspend { someRepo.getName(someName) }
        ) { a, b -> a.product { b } }
    }
}
the test doesn’t pass, it says
This job hasn't completed yet
when i execute
getResult
with
runBlockingTest
j
I don't think running arrow fx coroutines with kotlinx coroutines runner method will work as expected. Does this still fail when run with
Environment().unsafeRunAsync/unsafeRunSync
? If you need to bridge between kotlinx and arrow fx then you'll have to wait a bit, but there is a compat module in the works I think Edit: Look further down in this thread, it was already merged
s
okay that was successful. Thanks. But it is weird. I have other tests which use
bracketCase
and they run properly with kotlinx coroutines runner. And since the implementations are leveraging suspend and kotlinx coroutines, and the documentation says both libraries are interoperable with each other, I shouldn’t have the need to use
Environment()
if i am using
runBlocking
or
runBlockingTest
from kotlinx coroutines.
j
kotlinx
and
arrow fx
provide runners for kotlin couroutines (
suspend functions
). They can both be used to run
suspend
functions with all the benefits they each provide, but
kotlinx
and
arrow fx
compete with different approaches to things like for example cancellation
The important bit
kotlinx coroutines
!=
kotlin coroutines
which imo is terrible naming
s
Yes I understand that, but arrow docs says this : So I assumed it should work right ?
j
I guess that is talking about: https://github.com/arrow-kt/arrow-fx/pull/257 Which I wasn't aware of that it was already merged for a while^^ Interop is not as easy as simply swapping out the run function, but it looks as it is pretty easy to define extension functions for interop: https://github.com/arrow-kt/arrow-fx/blob/master/arrow-fx-coroutines-kotlinx-coroutines/src/main/kotlin/arrow/fx/coroutines/kotlinx/extensions.kt If you actually need
kotlinx
use those I guess, but if not it is better to just stick to
Environment
to run
arrow fx
.