sequencer logic for variable import

This commit is contained in:
Luke Page
2014-10-24 07:29:45 +01:00
parent 5f1f091168
commit 5202a1fc5f
2 changed files with 27 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
function ImportSequencer(onSequencerEmpty) {
this.imports = [];
this.variableImports = [];
this._onSequencerEmpty = onSequencerEmpty;
}
@@ -18,14 +19,26 @@ ImportSequencer.prototype.addImport = function(callback) {
};
};
ImportSequencer.prototype.addVariableImport = function(callback) {
this.variableImports.push(callback);
};
ImportSequencer.prototype.tryRun = function() {
while(this.imports.length > 0) {
var importItem = this.imports[0];
if (!importItem.isReady) {
return;
while(true) {
while(this.imports.length > 0) {
var importItem = this.imports[0];
if (!importItem.isReady) {
return;
}
this.imports = this.imports.slice(1);
importItem.callback.apply(null, importItem.args);
}
this.imports = this.imports.slice(1);
importItem.callback.apply(null, importItem.args);
if (this.variableImports.length === 0) {
break;
}
var variableImport = this.variableImports[0];
this.variableImports = this.variableImports.slice(1);
variableImport();
}
if (this._onSequencerEmpty) {
this._onSequencerEmpty();

View File

@@ -27,6 +27,7 @@ ImportVisitor.prototype = {
}
this.isFinished = true;
this._sequencer.tryRun();
if (this.importCount === 0) {
this._finish(error || this.error);
}
@@ -113,9 +114,13 @@ ImportVisitor.prototype = {
var subFinish = function(e) {
importVisitor.importCount--;
if (importVisitor.importCount === 0 && importVisitor.isFinished) {
importVisitor._finish(e || importVisitor.error);
} else if (e) {
if (importVisitor.isFinished) {
this._sequencer.tryRun();
if (importVisitor.importCount === 0) {
importVisitor._finish(e || importVisitor.error);
}
}
if (e) {
importVisitor.error = e;
}
};