L.C
09/13/2021, 10:47 AMtypealias AsyncCallback = (Result?, Throwable?) -> Unit
private val listeners = mutableListOf<Command>()
@ExperimentalUnsignedTypes
fun interface CommandInterface {
fun performAsync(
arg1: UByte,
arg2: UByte?,
arg3: ByteArray,
callback: AsyncCallback
)
}
@ExperimentalUnsignedTypes
data class Command(
val arg1: UByte,
val arg2: UByte? = null,
val arg3: AsyncCallback
)
private val executor = CommandInterface { arg1, arg2, arg3, callback ->
listeners.add(
Command(
arg1,
arg2,
callback = callback
)
)
// This method returns [Result] and resume [continuation]
action(arg3)
}
suspend fun perform(
arg1: UByte,
arg2: UByte?,
arg3: ByteArray
): Result? =
try {
suspendCoroutineWithTimeout(10000) { continuation ->
try {
continuation.invokeOnCancellation {
cancelRequest(arg1, arg2)
}
//Log.d(TAG,"arg1 type : ${arg1 is UByte}")
executor.performAsync(
arg1,
arg2,
arg3 = arg3
) { result, exception ->
when {
response == null ->
continuation.resumeWithException(Exception("Null point exception"))
exception != null ->
continuation.resumeWithException(exception)
else -> {
continuation.resume(result)
}
}
}
} catch (e: Throwable) {
e.message
continuation.cancel()
}
}
} catch (e: TimeoutCancellationException) {
cancelRequest(arg1,arg2)
null
}
When the app called perform() function, it got an error in a coroutine:abstract method “void CommandInterface.performAsync-vmjznIo(byte, kotlin.UByte, byte[], kotlin.jvm.functions.Function2)”
It seemed the Kotlin compiler recognised the first argument arg1 as byte, but the interface defined it as UByte.
The Kotlin plugin I am using is 1.5.30, AGP version is 7.0.2