Skip to content

Commit 94dbc80

Browse files
Merge pull request #322 from brendandburns/env
Close watches more cleanly.
2 parents 9e23b71 + 4770a53 commit 94dbc80

File tree

1 file changed

+5
-2
lines changed
  • util/src/main/java/io/kubernetes/client/util

1 file changed

+5
-2
lines changed

util/src/main/java/io/kubernetes/client/util/Watch.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static class Response<T> {
7070
Type watchType;
7171
ResponseBody response;
7272
JSON json;
73+
Call call;
7374

7475
/**
7576
* Creates a watch on a TYPENAME (T) using an API Client and a Call object.
@@ -105,16 +106,17 @@ public static <T> Watch<T> createWatch(ApiClient client, Call call, Type watchTy
105106
throw new ApiException(
106107
response.message(), response.code(), response.headers().toMultimap(), respBody);
107108
}
108-
return new Watch<>(client.getJSON(), response.body(), watchType);
109+
return new Watch<>(client.getJSON(), response.body(), watchType, call);
109110
} catch (IOException e) {
110111
throw new ApiException(e);
111112
}
112113
}
113114

114-
private Watch(JSON json, ResponseBody body, Type watchType) {
115+
private Watch(JSON json, ResponseBody body, Type watchType, Call call) {
115116
this.response = body;
116117
this.watchType = watchType;
117118
this.json = json;
119+
this.call = call;
118120
}
119121

120122
public Response<T> next() {
@@ -152,6 +154,7 @@ public void remove() {
152154
}
153155

154156
public void close() throws IOException {
157+
this.call.cancel();
155158
this.response.close();
156159
}
157160
}

0 commit comments

Comments
 (0)