googleapis / googleapis/java-genai

FR: AsyncSession.isClosed()

Open
#805 1 comment 0 reactions 1 assignee Claimed by @hemasekhar-p View on GitHub
priority: p3 type: feature request
Dominant language
Java
Stars
397
Forks
125
Avg merge
2d 8h
Merged PRs (30d)
41

Description

**Is your feature request related to a problem? Please describe.**

IMHO it would be useful for `class AsyncSession` to have an `isClosed()` kind of method.

This is because the async session doesn't just get closed by the user when invoking `close()` but can apparently also get closed by from server when its done ("Live session closed with code: 1000 and reason:").

To avoid the following, it would be useful if an application could check if it's been closed:

```
[ForkJoinPool.commonPool-worker-2] ERROR dev.enola.common.concurrent.Async - Async error for resource: GoogleLive sendRealtimeInput()
java.util.concurrent.CompletionException: org.java_websocket.exceptions.WebsocketNotConnectedException
at java.base/java.util.concurrent.CompletableFuture.wrapInCompletionException(CompletableFuture.java:323)
at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:359)
at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:364)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1828)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1817)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:511)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1450)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2019)
at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
Caused by: org.java_websocket.exceptions.WebsocketNotConnectedException
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:669)
at org.java_websocket.WebSocketImpl.send(WebSocketImpl.java:645)
at org.java_websocket.client.WebSocketClient.send(WebSocketClient.java:445)
at com.google.genai.AsyncSession.lambda$send$0(AsyncSession.java:110)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1825)
... 5 more
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.