File tree Expand file tree Collapse file tree
java/src/processing/mode/java/pdex Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments