SingleSWTRequest utility class now actually does what it is supposed to
authorFabian Stemmler <stemmler@in.tum.de>
Tue, 1 Oct 2019 00:42:21 +0000 (02:42 +0200)
committerFabian Stemmler <stemmler@in.tum.de>
Tue, 1 Oct 2019 00:51:24 +0000 (02:51 +0200)
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/util/SingleSWTRequest.java

index fa4d558..c4a1eee 100644 (file)
@@ -4,14 +4,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.eclipse.swt.widgets.Display;
 
+/**
+ * A utility class that requests the asynchronous execution of a Runnable in the SWT Thread. Making a new request before the old one is
+ * processed will override the old request.
+ */
 public class SingleSWTRequest
 {
        private AtomicBoolean waiting = new AtomicBoolean();
+       private Runnable request;
 
        public void request(Runnable request)
        {
                synchronized (waiting)
                {
+                       this.request = request;
                        if (!waiting.get())
                        {
                                waiting.set(true);
@@ -20,7 +26,7 @@ public class SingleSWTRequest
                                        synchronized (waiting)
                                        {
                                                waiting.set(false);
-                                               request.run();
+                                               this.request.run();
                                        }
                                });
                        }