I've got this code: ``` ...
# coroutines
r
I've got this code:
Copy code
return withTimeout(1000L) {
                                        suspendCancellableCoroutine { continuation ->
                                            mOnReceiveRfmUltralightCmdListener = { isSuc, data ->
                                                if (!isSuc) {
                                                    continuation.resumeWithException(
                                                        CardNoResponseException()
                                                    )
                                                } else {
                                                    continuation.resume(data)
                                                }
                                            }
                                            continuation.invokeOnCancellation {
                                                mOnReceiveRfmUltralightCmdListener = null
                                            }
                                            writeToReader()
                                        }
                                    }
Where
writeToReader()
is a
suspend
function - should I just use a
scope.launch
there?
m
Seems like you should move the
writeToReader
out of the
suspendCancellableCoroutine
unless that is what triggers the work callback to complete. In that case I would think that the suspendCancellableCoroutine should get moved into the suspending
writeToReader
, ideally not needing a member variable for the listener. It should then be returning the data, but a function called
writeToReader
returning data is strange.
r
Yeah, it's what triggers the work callback. Doesn't return any data, the callback is getting the data from the reader back.