For working non blocking the AWS2 SDK provides met...
# coroutines
b
For working non blocking the AWS2 SDK provides methods which returns CompleteableFuture<T>. Wrapping them into coroutines I wrote the following extension function (I don't like the name). My question would be, is that extension okay, or even already implemented in the standard coroutines library? If that extension is okay, what would you suggest as name for it?
Copy code
suspend fun <T> CompletableFuture<T>.suspending() : T = suspendCoroutine { cont ->
    whenComplete { v, e -> if(e==null) cont.resume(v) else cont.resumeWithException(e) }
}
It can be used for example to wrap the following AWS SDK method:
CompletableFuture<CopyObjectResponse> copyObject(CopyObjectRequest copyObjectRequest)
into
suspend fun S3AsyncClient.suspendingCopyObject(copyObjectRequest: CopyObjectRequest) : CopyObjectResponse = copyObject(copyObjectRequest).suspending()
s
There is a library that contains await for CompletableFutute
b
Cool, thanks.
d
One potential improvement would be to make it cancellable, see await implementation in above library