There is a way to make requirecall synchronization. Make CommonJS style:
var module = require('modulepath')
, factory , "" ... .
AMD requre(depsArray, factoryFn) , . "", "" .
, A B . - , " " define:
function someFunction(callback) {
var resultOfOuterCode = someResultOfCalculations
require([...], function(...) {
var resultOfTopRequireCode = someOtherResultOfCalculations
var semaphore = {
'count': 2
, 'callback':callback
, 'checkIfLast': function(){
this.count -= 1
if (!this.count) {
this.callback()
}
}
}
require([...], function(...) {
...
semaphore.checkIfLast()
});
require([...], function(...) {
semaphore.checkIfLast()
});
});
};
, require (dependArray, factoryFn) "" .