Created
November 20, 2013 02:56
-
-
Save likwid/7556910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function main3(scope) { | |
return function (data) { | |
scope.log(data.length); | |
}; | |
} | |
function main2(scope) { | |
return function (data) { | |
var innerPromise = $.get("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"); | |
innerPromise.then(main3(scope)); | |
return innerPromise; | |
}; | |
} | |
function main() { | |
var scope = console, | |
promise = $.get("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"); | |
promise.then(main2(scope)); | |
return promise; | |
} | |
function nestedMain() { | |
var promise = $.get("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"); | |
promise.then(function (data) { | |
var innerPromise = $.get("http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"); | |
innerPromise.then(function (data) { | |
console.log(data.length); | |
}); | |
return innerPromise; | |
}); | |
return promise; | |
} | |
function realMain2(data, nestedData) { | |
console.log(_.isEqual(data.length,nestedData.length)); | |
} | |
function realMain(dataPromise,nestedDataPromise) { | |
$.when(dataPromise, nestedDataPromise).done(realMain2); | |
} | |
$.when(main(),nestedMain()).done(realMain); | |
var actors = (function() { | |
function send(actor, signal, args) { | |
return actor.apply(null, [signal].concat(args)); | |
}; | |
function actor(table) { | |
var executor = function (signal) { | |
var slot = table[signal] || function() { | |
throw "No slot available for signal: "+signal; | |
} | |
return slot.apply(null, [executor].concat(_.rest(_.toArray(arguments)))); | |
}; | |
return executor; | |
}; | |
return { | |
send: send, | |
actor: actor | |
}; | |
})(); | |
var actorMain = actors.actor({ | |
"start": function (self) { | |
$.when(main(), nestedMain()).done(function () { | |
actors.send(self, "level1", _.toArray(arguments)); | |
}); | |
}, | |
"level1": function (self, mainPromise, nestedMainPromise) { | |
$.when(mainPromise, nestedMainPromise).done(function () { | |
actors.send(self, "finished", _.toArray(arguments)); | |
}); | |
}, | |
"finished": function (self, mainResult, nestedResult) { | |
console.log(_.isEqual(mainResult.length, nestedResult.length)); | |
} | |
}); | |
actors.send(actorMain, "start"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment