diff options
author | Leif Åstrand <legioth@gmail.com> | 2017-11-07 13:21:06 +0200 |
---|---|---|
committer | Pekka Maanpää <pekkamaa@vaadin.com> | 2017-11-07 13:21:06 +0200 |
commit | 0a3a6c0293ed3dc45740fac30738e81b920c084d (patch) | |
tree | af39d9ee08615d0a5f690536e87b26a47968021b | |
parent | b5b57375a3b785d758e09a4f27d3023b87e6f339 (diff) | |
download | vaadin-framework-0a3a6c0293ed3dc45740fac30738e81b920c084d.tar.gz vaadin-framework-0a3a6c0293ed3dc45740fac30738e81b920c084d.zip |
Skip scheduled flush if clear() is called (#10289)
Based on vaadin/flow#2834
-rw-r--r-- | client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java index fc66d8a502..f3c3ace3c2 100644 --- a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java +++ b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java @@ -21,7 +21,6 @@ import java.util.LinkedHashMap; import java.util.logging.Logger; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ConnectorMap; import com.vaadin.client.metadata.Method; @@ -43,6 +42,9 @@ import elemental.json.JsonValue; * @author Vaadin Ltd */ public class ServerRpcQueue { + private static final Runnable NO_OP = () -> { + // NOOP + }; /** * The pending method invocations that will be send to the server by @@ -60,7 +62,7 @@ public class ServerRpcQueue { protected ApplicationConnection connection; private boolean flushPending = false; - private boolean flushScheduled = false; + private Runnable doFlushStrategy = NO_OP; public ServerRpcQueue() { @@ -147,6 +149,7 @@ public class ServerRpcQueue { // Keep tag string short lastInvocationTag = 0; flushPending = false; + doFlushStrategy = NO_OP; } /** @@ -182,23 +185,27 @@ public class ServerRpcQueue { * Triggers a send of server RPC and legacy variable changes to the server. */ public void flush() { - if (flushScheduled || isEmpty()) { + if (isFlushScheduled() || isEmpty()) { return; } flushPending = true; - flushScheduled = true; - Scheduler.get().scheduleFinally(scheduledFlushCommand); + doFlushStrategy = this::doFlush; + Scheduler.get().scheduleFinally(() -> doFlushStrategy.run()); } - private final ScheduledCommand scheduledFlushCommand = () -> { - flushScheduled = false; + private void doFlush() { + doFlushStrategy = NO_OP; if (!isFlushPending()) { // Somebody else cleared the queue before we had the chance return; } connection.getMessageSender().sendInvocationsToServer(); - }; + } + + private boolean isFlushScheduled() { + return NO_OP != doFlushStrategy; + } /** * Checks if a flush operation is pending. |