Ricardo C.
10/16/2020, 2:59 PMRicardo C.
10/16/2020, 2:59 PMsuspend fun <R, E> invokeMethod(
name: String,
onSuccessClass: Class<R>,
onErrorClass: Class<E>,
vararg args: Any
): Result<R> = withContext(dispatcher) {
suspendCoroutine { continuation ->
val onSuccess = { result: String ->
val data = parseJson(onSuccessClass, result)
continuation.resume(Result.success(data))
}
val onError = { error: String ->
val data = parseJson(onErrorClass, error)
continuation.resume(Result.failure(DataException(data.toString())))
}
runtime.invokeMethod(name, onSuccess, onError, *args)
}
}
Ricardo C.
10/16/2020, 3:01 PMRicardo C.
10/16/2020, 3:09 PMRicardo C.
10/16/2020, 3:29 PMRicardo C.
10/16/2020, 3:29 PMMarc Knaup
10/16/2020, 3:37 PMResult
is an inline class
which are still experimental. There are edge cases where they aren’t handled properly by the compiler.
I guess your Result
is unintentionally unwrapped which leads to the exception.Marc Knaup
10/16/2020, 3:38 PMResult
isn’t supposed to be used as a general purpose return type.Ricardo C.
10/16/2020, 3:42 PMlouiscad
10/16/2020, 4:00 PMMarc Knaup
10/16/2020, 4:00 PMinline
days after because I keep getting exceptions 😄