streetsofboston
02/12/2019, 4:03 PMfx { ... } 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.raulraja
02/12/2019, 4:16 PMraulraja
02/12/2019, 4:16 PMraulraja
02/12/2019, 4:17 PMraulraja
02/12/2019, 4:17 PMraulraja
02/12/2019, 4:17 PMraulraja
02/12/2019, 4:17 PMstreetsofboston
02/12/2019, 4:18 PMoverride 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?raulraja
02/12/2019, 4:19 PMraulraja
02/12/2019, 4:19 PMraulraja
02/12/2019, 4:20 PMraulraja
02/12/2019, 4:20 PMraulraja
02/12/2019, 4:20 PMstreetsofboston
02/12/2019, 4:21 PMservice.getReverse(....).await() is suspending (Deffered.await)streetsofboston
02/12/2019, 4:21 PMfx 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?streetsofboston
02/12/2019, 4:22 PMoverride 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()
}
}streetsofboston
02/12/2019, 4:24 PMfx { ... } 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) 🙂raulraja
02/12/2019, 5:44 PMfx when you deal with things like this is which is io fx actually returns a suspended functionraulraja
02/12/2019, 5:44 PMsuspend landraulraja
02/12/2019, 5:44 PM