Skip to content

Commit 1a5af94

Browse files
committed
flush STDOUT before sleep
1 parent 68f1308 commit 1a5af94

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/org/perlonjava/runtime/RuntimeIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class RuntimeIO implements RuntimeScalarReference {
6464

6565
// State flags
6666
private boolean isEOF;
67-
private boolean needFlush;
67+
boolean needFlush;
6868

6969
// Constructor to initialize buffers
7070
public RuntimeIO() {

src/main/java/org/perlonjava/runtime/RuntimeScalar.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.concurrent.TimeUnit;
2626

2727
import static org.perlonjava.runtime.GlobalContext.getGlobalVariable;
28+
import static org.perlonjava.runtime.RuntimeIO.stderr;
29+
import static org.perlonjava.runtime.RuntimeIO.stdout;
2830
import static org.perlonjava.runtime.RuntimeScalarCache.*;
2931

3032
/**
@@ -1560,6 +1562,15 @@ public RuntimeScalar hex() {
15601562
}
15611563

15621564
public RuntimeScalar sleep() {
1565+
1566+
// Flush stdout and stderr before reading, in case we are displaying a prompt
1567+
if (stdout.needFlush) {
1568+
stdout.flush();
1569+
}
1570+
if (stderr.needFlush) {
1571+
stderr.flush();
1572+
}
1573+
15631574
long s = (long) this.getDouble() * 1000;
15641575
try {
15651576
TimeUnit.MILLISECONDS.sleep(s);

0 commit comments

Comments
 (0)