However, and to extend the scenario, a call to load multiple JavaScript libraries through
LoadLib_STH proffers no guarantee over the order in which the requested code will arrive. Given this,
and if using the proprietary synchronisation mechanism outlined above, do be sure that the global 'end-of-file' function call does not
attempt to call a method in one of the other libraries that are being loaded. The corrollary to this is that the synchronisation-onus
lies with the caller(s) of LoadLib_STH.
An alternative, however to using proprietary solution is to use the
CreateEventMarshaller
library function provided on this site. A call to this function will return an EventMarshaller object to which 'events' can be posted
such that an 'action' (a reference to a function) is associated with a given event. When the number of events posted to a given marshaller
reaches a user-defined limit, the marshaller will dispatch each action (i.e. call the function on the end of each reference) in the order
of any priorities that have been assigned to those events.
Example Two illustrates these concepts in action. Here two libraries are depicted that, once loaded, will each call a function in the
main code-body. Instead of attempting to invoke the methods in the respective libraries, these two functions each post an event to
an event marshaller that has a queue size of two.
This approach means that it is immaterial which library is loaded first, as the code that makes use of their respective objects and
functions is executed only once the other has loaded. Moreover, the correct execution order - where Lib2 code must execute before
Lib1 code - is guaranteed because the loading events are assigned a priority of one and zero.