<@U4UGS5FC7> or <@U0B8UEMV1> After this bug ( <htt...
# arrow
s
@raulraja or @pakoito After this bug ( https://github.com/arrow-kt/arrow/issues/1295 ) is fixed, will the
fx { ... }
calls themselves be blocking or suspending? Looking at the Arrow code, the
fx { ... }
calls return a
returnedMonad
immediately (which could cause that #1295 bug). If this is fixed and its suspending lambda does not continue immediately, will the
fx
call be blocking or suspending to get the correct monad to be returned by it? I’m asking this especially for the
fx
calls returning
Either
,
Try
, etc values.
r
With the latest Fx changes it will be all suspended and you don't need to use io or anything
You are fine using suspend and returning either
All combinators will be available globally without type class dependencies
Just suspend function composition
You can choose to run on arrow or coroutines core runBlocking and launch
On arrow you would use the unsafe runners
s
As an example:
Copy code
override suspend fun getReverse(latitude: Double, longitude: Double): Either<GeoError, String> {
        val tryCity: Try<String> = fx {
            val reverse = effect { service.getReverse(GeoLocation(latitude, longitude)).await() }
            (!reverse).city.orEmpty()
        }

        return tryCity.toEither { it.asGeoError }
    }
The
getReverse
method here must be
suspend
after the fix, because
fx
will be suspending as well, correct?
r
That is the either fx
I'm talking about using as IO
You can I stantiate the try outside of it's fx
The try constructor works in the environment not suspended
The use the Fx block to compose
s
But
service.getReverse(....).await()
is suspending (Deffered.await)
Ah.. you mean not use
fx
at all here, because I’m just creating one
Either
(or
Try
). Use
fx
here only if I would’ve had a bunch of
service
calls returning
Either
values, to easily combine/compose these multiple
Either
values into one value then returned by the call to
fx
. Is this correct?
Copy code
override suspend fun getReverse(latitude: Double, longitude: Double): Either<GeoError, String> {
        return try {
            service.getReverse(GeoLocation(latitude, longitude)).await()
                .city
                .orEmpty()
                .just()
        } catch (e: Throwable) {
            e.asGeoError
                .raiseError()
        }
    }
I’m still struggling to figure out when to use
fx { ... }
returning a value (
Either
,
Try
, etc) or when to just use a plain call to a
suspend
function (inside the body of a
suspend
function) 🙂
r
in the new version of
fx
when you deal with things like this is which is
io
fx actually returns a suspended function
so you are fine staying in
suspend
land
you will be able to use attempt, handleErrorWith etc... in those as well