google / java-photoslibrary

Java client library for the Google Photos Library API
http://developers.google.com/photos
Apache License 2.0
108 stars 59 forks source link

Impossible to interrupt a long-running media item upload if invoked via blocking method #43

Open ylexus opened 3 years ago

ylexus commented 3 years ago

As per https://github.com/google/java-photoslibrary/issues/30#issuecomment-904352898, I can confirm that interrupting the upload via interrupting the thread blocked on client.uploadMediaItemCallable().futureCall(uploadRequest).get() works. However, as before, both client.uploadMediaItem() and client.uploadMediaItemCallable().call(uploadRequest) block uninterruptibly, because ApiExceptions.callAndTranslateApiException calls Futures.getUnchecked(future), which blocks uninterruptibly by design.

I don't know in which situation one would ever want to block uninterruptibly to be honest. It's a road to unresponsive apps, leaking threads etc. Also, the behaviour should be symmetrical regardless of how you invoke the API. At the very least, the interrupt behaviour must be documented.