Skip to content

Commit 926ce44

Browse files
committed
PPS: wait for running callbacks to finish before publishing new result
1 parent 99408df commit 926ce44

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

java/src/processing/mode/java/pdex/PreprocessingService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public PreprocessingService(JavaEditor editor) {
112112
private void mainLoop() {
113113
running = true;
114114
PreprocessedSketch prevResult = null;
115+
CompletableFuture<?> runningCallbacks = null;
115116
Messages.log("PPS: Hi!");
116117
while (running) {
117118
try {
@@ -126,8 +127,18 @@ private void mainLoop() {
126127

127128
prevResult = preprocessSketch(prevResult);
128129

130+
// Wait until callbacks finish before firing new wave
131+
// If new request arrives while waiting, break out and start preprocessing
132+
while (requestQueue.isEmpty() && runningCallbacks != null) {
133+
try {
134+
runningCallbacks.get(10, TimeUnit.MILLISECONDS);
135+
runningCallbacks = null;
136+
} catch (TimeoutException e) { }
137+
}
138+
129139
synchronized (requestLock) {
130140
if (requestQueue.isEmpty()) {
141+
runningCallbacks = lastCallback;
131142
Messages.log("PPS: Done");
132143
preprocessingTask.complete(prevResult);
133144
}

0 commit comments

Comments
 (0)