Fixed runnable to allow acces to pending messages

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2018-11-25 11:22:37 -05:00
parent 5e5cc2a1cd
commit bcd0faceef
2 changed files with 44 additions and 2 deletions

View File

@@ -145,6 +145,9 @@ public final class ReadingRunnable implements Runnable {
* @throws IOException if the pipe is closed */
public String getMessage() throws IOException {
synchronized (lock) {
if (!messages.isEmpty()) {
return messages.poll();
}
if (!running) {
throw new IOException(CLOSED_PIPE);
}
@@ -164,6 +167,9 @@ public final class ReadingRunnable implements Runnable {
* @throws IOException if the input was closed */
public String getNextMessage(final long timeout) throws IOException {
synchronized (lock) {
if (!messages.isEmpty()) {
return messages.poll();
}
if (!running) {
throw new IOException(CLOSED_PIPE);
}