I am trying to write a suspend function that can listen to cancellation of continuation, and invoke a suspended callback. Here is what I am looking at:
Copy code
suspend fun <T> PreparedStatement.withCancellation(callback: suspend () -> T): T {
val stmt = this
suspendCancellableCoroutine { cont ->
cont.invokeOnCancellation {
stmt.cancel()
}
}
return callback()
}