r.js
/**
         * Checks if all modules for a context are loaded, and if so, evaluates the
         * new ones in right dependency order.
         *
         * @private
         */
Checks if all modules for a context are loaded, and if so, evaluates the
new ones in right dependency order.

@private
Checks if all modules for a context are loaded and if so evaluates the new ones in right dependency order . @private
function checkLoaded() {
            var waitInterval = config.waitSeconds * 1000,
                expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
                noLoads = "", hasLoadedProp = false, stillLoading = false,
                cycleDeps = [],
                i, prop, err, manager, cycleManager, moduleDeps;
            if (context.pausedCount > 0) {
                return undefined;
            }
            if (config.priorityWait) {
                if (isPriorityDone()) {
                    resume();
                } else {
                    return undefined;
                }
            }
            for (prop in loaded) {
                if (!(prop in empty)) {
                    hasLoadedProp = true;
                    if (!loaded[prop]) {
                        if (expired) {
                            noLoads += prop + " ";
                        } else {
                            stillLoading = true;
                            if (prop.indexOf('!') === -1) {
                                cycleDeps = [];
                                break;
                            } else {
                                moduleDeps = managerCallbacks[prop] && managerCallbacks[prop].moduleDeps;
                                if (moduleDeps) {
                                    cycleDeps.push.apply(cycleDeps, moduleDeps);
                                }
                            }
                        }
                    }
                }
            }
            if (!hasLoadedProp && !context.waitCount) {
                return undefined;
            }
            if (expired && noLoads) {
                err = makeError("timeout", "Load timeout for modules: " + noLoads);
                err.requireType = "timeout";
                err.requireModules = noLoads;
                return req.onError(err);
            }
            if (stillLoading && cycleDeps.length) {
                for (i = 0; (manager = waiting[cycleDeps[i]]); i++) {
                    if ((cycleManager = findCycle(manager, {}))) {
                        forceExec(cycleManager, {});
                        break;
                    }
                }
            }
            if (!expired && (stillLoading || context.scriptCount)) {
                if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
                    checkLoadedTimeoutId = setTimeout(function () {
                        checkLoadedTimeoutId = 0;
                        checkLoaded();
                    }, 50);
                }
                return undefined;
            }
            if (context.waitCount) {
                for (i = 0; (manager = waitAry[i]); i++) {
                    forceExec(manager, {});
                }
                if (context.paused.length) {
                    resume();
                }
                if (checkLoadedDepth < 5) {
                    checkLoadedDepth += 1;
                    checkLoaded();
                }
            }
            checkLoadedDepth = 0;
            req.checkReadyState();
            return undefined;
        }
function checkLoaded ( ) { var waitInterval = config . waitSeconds * 1000 , expired = waitInterval && ( context . startTime + waitInterval ) < new Date ( ) . getTime ( ) , noLoads = "" , hasLoadedProp = false , stillLoading = false , cycleDeps = [ ] , i , prop , err , manager , cycleManager , moduleDeps ; if ( context . pausedCount > 0 ) { return undefined ; } if ( config . priorityWait ) { if ( isPriorityDone ( ) ) { resume ( ) ; } else { return undefined ; } } for ( prop in loaded ) { if ( ! ( prop in empty ) ) { hasLoadedProp = true ; if ( ! loaded [ prop ] ) { if ( expired ) { noLoads += prop + " " ; } else { stillLoading = true ; if ( prop . indexOf ( '!' ) === - 1 ) { cycleDeps = [ ] ; break ; } else { moduleDeps = managerCallbacks [ prop ] && managerCallbacks [ prop ] . moduleDeps ; if ( moduleDeps ) { cycleDeps . push . apply ( cycleDeps , moduleDeps ) ; } } } } } } if ( ! hasLoadedProp && ! context . waitCount ) { return undefined ; } if ( expired && noLoads ) { err = makeError ( "timeout" , "Load timeout for modules: " + noLoads ) ; err . requireType = "timeout" ; err . requireModules = noLoads ; return req . onError ( err ) ; } if ( stillLoading && cycleDeps . length ) { for ( i = 0 ; ( manager = waiting [ cycleDeps [ i ] ] ) ; i ++ ) { if ( ( cycleManager = findCycle ( manager , { } ) ) ) { forceExec ( cycleManager , { } ) ; break ; } } } if ( ! expired && ( stillLoading || context . scriptCount ) ) { if ( ( isBrowser || isWebWorker ) && ! checkLoadedTimeoutId ) { checkLoadedTimeoutId = setTimeout ( function ( ) { checkLoadedTimeoutId = 0 ; checkLoaded ( ) ; } , 50 ) ; } return undefined ; } if ( context . waitCount ) { for ( i = 0 ; ( manager = waitAry [ i ] ) ; i ++ ) { forceExec ( manager , { } ) ; } if ( context . paused . length ) { resume ( ) ; } if ( checkLoadedDepth < 5 ) { checkLoadedDepth += 1 ; checkLoaded ( ) ; } } checkLoadedDepth = 0 ; req . checkReadyState ( ) ; return undefined ; }
Checks if all modules for a context are loaded, and if so, evaluates the
 new ones in right dependency order.
Checks if all modules for a context are loaded and if so evaluates the new ones in right dependency order .
//It is possible to disable the wait interval by using waitSeconds of 0. //If there are items still in the paused queue processing wait. //This is particularly important in the sync case where each paused //item is processed right away but there may be more waiting. //Determine if priority loading is done. If so clear the priority. If //not, then do not check //Call resume, since it could have //some waiting dependencies to trace. //See if anything is still in flight. //No reason to keep looking for unfinished //loading. If the only stillLoading is a //plugin resource though, keep going, //because it may be that a plugin resource //is waiting on a non-plugin cycle. //Check for exit conditions. //If the loaded object had no items, then the rest of //the work below does not need to be done. //If wait time expired, throw error of unloaded modules. //If still loading but a plugin is waiting on a regular module cycle //break the cycle. //If still waiting on loads, and the waiting load is something //other than a plugin resource, or there are still outstanding //scripts, then just try back later. //Something is still waiting to load. Wait for it, but only //if a timeout is not already in effect. //If still have items in the waiting cue, but all modules have //been loaded, then it means there are some circular dependencies //that need to be broken. //However, as a waiting thing is fired, then it can add items to //the waiting cue, and those items should not be fired yet, so //make sure to redo the checkLoaded call after breaking a single //cycle, if nothing else loaded then this logic will pick it up //again. //Cycle through the waitAry, and call items in sequence. //If anything got placed in the paused queue, run it down. //Only allow this recursion to a certain depth. Only //triggered by errors in calling a module in which its //modules waiting on it cannot finish loading, or some circular //dependencies that then may add more dependencies. //The value of 5 is a bit arbitrary. Hopefully just one extra //pass, or two for the case of circular dependencies generating //more work that gets resolved in the sync node case. //Check for DOM ready, and nothing is waiting across contexts.