coreRuntime/src/sc/bind/BindingContext.java
public boolean dispatchEvents(Object sync) {
      BindingEvent oldEvent;
      BindingEvent toExecute = null, lastToExecute = null;
      float priority = UNSET_PRIORITY;
      BindingEvent prevEvent = null, nextEvent;
      List<BindingEvent> runList = null;
      boolean queuedLastEvent = false;
      boolean any = false;

      synchronized (this) {
         /**
          * Go through the list and pull out any events which match this sync flag.
          */
         for (oldEvent = queuedEvents; oldEvent != null; oldEvent = nextEvent) {
            nextEvent = oldEvent.next;

            // If we are executing this event, pull it out of the list and put it on the toExecute list
            if (sync == null || oldEvent.listener.getSync() == null || oldEvent.listener.getSync().equals(sync)) {
               if (priority != oldEvent.listener.getPriority()) {
                  if (toExecute != null) {
                     if (runList == null)
                        runList = new ArrayList<BindingEvent>();
                     runList.add(toExecute);
                  }

                  // Set the new priority and start out with the new next guy
                  priority = oldEvent.listener.getPriority();
                  toExecute = oldEvent;
                  lastToExecute = oldEvent;
               }
               else {
                  // Should only get here the second time once we've run the above
                  assert lastToExecute != null;
                  lastToExecute.next = oldEvent;
                  lastToExecute = oldEvent;
               }

               if (prevEvent == null)
                   queuedEvents = nextEvent;
               else {
                  if (queuedEvents == oldEvent)
                     queuedEvents = nextEvent;

                  // Only if it is still in the queued events list, need to remove it
                  if (!queuedLastEvent)
                     prevEvent.next = nextEvent;
               }
               oldEvent.next = null;
               queuedLastEvent = true;
            }
            else
               queuedLastEvent = false;
            prevEvent = oldEvent;
         }
      }
      // If we have more than one priority, the list stores the lists that need to be run first
      if (runList != null) {
         int sz = runList.size();
         any = true;
         for (int i = 0; i < sz; i++) {
            BindingEvent be = runList.get(i);
            // Dispatch all of the events with the same priority.
            doDispatch(be);
         }
      }
      if (toExecute != null) {
         doDispatch(toExecute);
         any = true;
      }
      return any;
   }
/**
    * Called when we want to dispatch some of the pending events  We go through and pull out the events which
    * match the sync flag.  All events of the same priority are batched up in this method and sent to doDispatch
    * where dependencies are resolved.
    *
    * @param sync
    */
Called when we want to dispatch some of the pending events  We go through and pull out the events which
match the sync flag.  All events of the same priority are batched up in this method and sent to doDispatch
where dependencies are resolved.

@param sync
Called when we want to dispatch some of the pending events We go through and pull out the events which match the sync flag . All events of the same priority are batched up in this method and sent to doDispatch where dependencies are resolved . @param sync
public boolean dispatchEvents(Object sync) {
      BindingEvent oldEvent;
      BindingEvent toExecute = null, lastToExecute = null;
      float priority = UNSET_PRIORITY;
      BindingEvent prevEvent = null, nextEvent;
      List<BindingEvent> runList = null;
      boolean queuedLastEvent = false;
      boolean any = false;
      synchronized (this) {
         /**
          * Go through the list and pull out any events which match this sync flag.
          */
         for (oldEvent = queuedEvents; oldEvent != null; oldEvent = nextEvent) {
            nextEvent = oldEvent.next;
            if (sync == null || oldEvent.listener.getSync() == null || oldEvent.listener.getSync().equals(sync)) {
               if (priority != oldEvent.listener.getPriority()) {
                  if (toExecute != null) {
                     if (runList == null)
                        runList = new ArrayList<BindingEvent>();
                     runList.add(toExecute);
                  }
                  priority = oldEvent.listener.getPriority();
                  toExecute = oldEvent;
                  lastToExecute = oldEvent;
               }
               else {
                  assert lastToExecute != null;
                  lastToExecute.next = oldEvent;
                  lastToExecute = oldEvent;
               }
               if (prevEvent == null)
                   queuedEvents = nextEvent;
               else {
                  if (queuedEvents == oldEvent)
                     queuedEvents = nextEvent;
                  if (!queuedLastEvent)
                     prevEvent.next = nextEvent;
               }
               oldEvent.next = null;
               queuedLastEvent = true;
            }
            else
               queuedLastEvent = false;
            prevEvent = oldEvent;
         }
      }
      if (runList != null) {
         int sz = runList.size();
         any = true;
         for (int i = 0; i < sz; i++) {
            BindingEvent be = runList.get(i);
            doDispatch(be);
         }
      }
      if (toExecute != null) {
         doDispatch(toExecute);
         any = true;
      }
      return any;
   }
public boolean dispatchEvents ( Object sync ) { BindingEvent oldEvent ; BindingEvent toExecute = null , lastToExecute = null ; float priority = UNSET_PRIORITY ; BindingEvent prevEvent = null , nextEvent ; List < BindingEvent > runList = null ; boolean queuedLastEvent = false ; boolean any = false ; synchronized ( this ) { /**
          * Go through the list and pull out any events which match this sync flag.
          */ for ( oldEvent = queuedEvents ; oldEvent != null ; oldEvent = nextEvent ) { nextEvent = oldEvent . next ; if ( sync == null || oldEvent . listener . getSync ( ) == null || oldEvent . listener . getSync ( ) . equals ( sync ) ) { if ( priority != oldEvent . listener . getPriority ( ) ) { if ( toExecute != null ) { if ( runList == null ) runList = new ArrayList < BindingEvent > ( ) ; runList . add ( toExecute ) ; } priority = oldEvent . listener . getPriority ( ) ; toExecute = oldEvent ; lastToExecute = oldEvent ; } else { assert lastToExecute != null ; lastToExecute . next = oldEvent ; lastToExecute = oldEvent ; } if ( prevEvent == null ) queuedEvents = nextEvent ; else { if ( queuedEvents == oldEvent ) queuedEvents = nextEvent ; if ( ! queuedLastEvent ) prevEvent . next = nextEvent ; } oldEvent . next = null ; queuedLastEvent = true ; } else queuedLastEvent = false ; prevEvent = oldEvent ; } } if ( runList != null ) { int sz = runList . size ( ) ; any = true ; for ( int i = 0 ; i < sz ; i ++ ) { BindingEvent be = runList . get ( i ) ; doDispatch ( be ) ; } } if ( toExecute != null ) { doDispatch ( toExecute ) ; any = true ; } return any ; }
Called when we want to dispatch some of the pending events  We go through and pull out the events which
 match the sync flag.
Called when we want to dispatch some of the pending events We go through and pull out the events which match the sync flag .
// If we are executing this event, pull it out of the list and put it on the toExecute list // Set the new priority and start out with the new next guy // Should only get here the second time once we've run the above // Only if it is still in the queued events list, need to remove it // If we have more than one priority, the list stores the lists that need to be run first // Dispatch all of the events with the same priority.