Skip to content

Commit 3811045

Browse files
committed
Busy-wait until the input is ready
1 parent 5dad1ac commit 3811045

File tree

1 file changed

+19
-13
lines changed
  • x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli

1 file changed

+19
-13
lines changed

x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/cli/EmbeddedCli.java

+19-13
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,6 @@ protected boolean addShutdownHook() {
127127
exec.start();
128128

129129
try {
130-
// Busy-wait until the input is ready
131-
while (in.ready() == false) {
132-
try {
133-
Thread.sleep(100);
134-
} catch (InterruptedException e) {
135-
Thread.currentThread().interrupt();
136-
throw new IllegalStateException(e);
137-
}
138-
}
139130
// Feed it passwords if needed
140131
if (security != null) {
141132
String passwordPrompt = "[?1h=[?2004hpassword: ";
@@ -224,7 +215,7 @@ public void close() throws IOException {
224215
out.flush();
225216
List<String> nonQuit = new ArrayList<>();
226217
String line;
227-
while (in.ready()) {
218+
while (true) {
228219
line = readLine();
229220
if (line == null) {
230221
fail("got EOF before [Bye!]. Extras " + nonQuit);
@@ -306,8 +297,14 @@ public String readLine() throws IOException {
306297
*
307298
* `null` means EOF so we should just pass that back through.
308299
*/
309-
if (in.ready() == false) {
310-
return "";
300+
// Busy-wait until the input is ready
301+
while (in.ready() == false) {
302+
try {
303+
Thread.sleep(100);
304+
} catch (InterruptedException e) {
305+
Thread.currentThread().interrupt();
306+
throw new IllegalStateException(e);
307+
}
311308
}
312309
String line = in.readLine();
313310
line = line == null ? null : line.replace("\u001B", "");
@@ -316,9 +313,18 @@ public String readLine() throws IOException {
316313
}
317314

318315
private String readUntil(Predicate<String> end) throws IOException {
316+
// Busy-wait until the input is ready
317+
while (in.ready() == false) {
318+
try {
319+
Thread.sleep(100);
320+
} catch (InterruptedException e) {
321+
Thread.currentThread().interrupt();
322+
throw new IllegalStateException(e);
323+
}
324+
}
319325
StringBuilder b = new StringBuilder();
320326
String result = "";
321-
while (in.ready()) {
327+
while (true) {
322328
int c = in.read();
323329
if (c == -1) {
324330
throw new IOException("got eof before end");

0 commit comments

Comments
 (0)