<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.micromanager.utils;

import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;

/**
 *
 * @author arthur and henry
 */
public class GUIUpdater {

   AtomicReference<Runnable> latestTask = new AtomicReference<Runnable>();

   /*
    * Post a task for running on the EDT thread. If multiple
    * tasks pile up, only the most recent will run.
    */
   public void post(Runnable task) {
      latestTask.set(task);
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            final Runnable taskToRun = latestTask.getAndSet(null);
            if (taskToRun != null) {
               taskToRun.run();
            }
         }
      });
   }
}<commit_msg>redesign of GUIUpdater, because old version allowed events to pile up<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.micromanager.utils;

import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;

/**
 *
 * @author arthur and henry
 */
public class GUIUpdater {

   AtomicReference<Runnable> latestTask = new AtomicReference<Runnable>();

   /*
    * Post a task for running on the EDT thread. If multiple
    * tasks pile up, only the most recent will run.
    */
   public void post(Runnable task) {
      Runnable oldTask = latestTask.getAndSet(task);
      if (oldTask == null) {
         SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               final Runnable taskToRun = latestTask.getAndSet(null);
               taskToRun.run();
            }
         });
      }
   }
}
{'fraction_non_alphanumeric': 0.0979498861047836, 'fraction_numerical': 0.0, 'mean_word_length': 2.593047034764826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4147824', 'n_tokens_mistral': 522, 'n_tokens_neox': 503, 'n_words': 152}