Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

* | |

  Show Posts
Pages: [1]
1  PureMVC Manifold / Standard Version / as3 and concurrency on: December 23, 2009, 10:06:55
Hello,

  I was curious if anyone had any clarification on how Flash AS3 deals with threads? I noticed the following code in the View, and I wasn't sure if it was left for compatability with other more concurrent languages (Java,C,etc)

  Could anyone give an example where the notifiers might be modified during the notification loop?

PureMVC_AS3_2_0_4
[org/puremvc/as3/core/View.as]

{{{
96 :       /**
97 :        * Notify the <code>IObservers</code> for a particular <code>INotification</code>.
98 :        *
99 :        * <P>
100 :        * All previously attached <code>IObservers</code> for this <code>INotification</code>'s
101 :        * list are notified and are passed a reference to the <code>INotification</code> in
102 :        * the order in which they were registered.</P>
103 :        *
104 :        * @param notification the <code>INotification</code> to notify <code>IObservers</code> of.
105 :        */
106 :       public function notifyObservers( notification:INotification ) : void
107 :       {
108 :          if( observerMap[ notification.getName() ] != null ) {
109 :             
110 :             // Get a reference to the observers list for this notification name
111 :             var observers_ref:Array = observerMap[ notification.getName() ] as Array;
112 :
113 :             // Copy observers from reference array to working array,
114 :             // since the reference array may change during the notification loop
115 :                var observers:Array = new Array();
116 :                var observer:IObserver;
117 :             for (var i:Number = 0; i < observers_ref.length; i++) {
118 :                observer = observers_ref[ i ] as IObserver;
119 :                observers.push( observer );
120 :             }
121 :             
122 :             // Notify Observers from the working array            
123 :             for (i = 0; i < observers.length; i++) {
124 :                observer = observers[ i ] as IObserver;
125 :                observer.notifyObserver( notification );
126 :             }
127 :          }
128 :       }
}}}

  Also, if such a thing could occur, what thoughts did anyone have on using a more of an optimistic approach to the notification list - such as immutables (since it seems like it might not change nearly as often as notifications will be thrown).

thanks,
Paul
Pages: [1]