Last active
December 10, 2015 14:08
-
-
Save Ivanca/4445537 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /************** | |
| * Con promesas | |
| **************/ | |
| var promise = foo().then(function(){ | |
| var promise = new Promise(); | |
| asyncFunction(function(){ | |
| // It has to know there is no need to merge it to a received object in order to | |
| // do this; | |
| var data = {key1:0x111}; | |
| promise.done(data); | |
| }) | |
| return promise; | |
| }).then(function(data){ | |
| var promise = new Promise(); | |
| asyncFunction(function(){ | |
| // It has to know the previous | |
| // result was an OBJECT in order to do this | |
| data.key2 = 0x222; | |
| promise.done(data); | |
| }) | |
| return promise; | |
| },function(err, data, promise){ | |
| if(err) data.error = true; | |
| promise.done(data); | |
| }).parallel(function(data){ | |
| var promise = new Promise(); | |
| asyncFunction(function(){ | |
| data.key2 += 0x333; | |
| promise.done(data); | |
| }); | |
| return promise; | |
| }).parallel(function(data){ | |
| var promise.done(data); | |
| asyncFunction(function(){ | |
| data.key2 += 0x444; | |
| promise.done(data); | |
| }) | |
| return promise; | |
| }); | |
| promise.then(function(){ | |
| console.log("Por Fin!"); | |
| }); | |
| /************** | |
| * Sin promesas | |
| **************/ | |
| foo(function(){ | |
| var data = {}; | |
| asyncFunction(function(){ | |
| data.key1 = 0x111; | |
| asyncFunction(function(err){ | |
| if(err){ | |
| data.error = true; | |
| return; | |
| } | |
| data.key2 = 0x222; | |
| parallel(); | |
| }); | |
| }); | |
| var parallel = function(){ | |
| var count = 0; | |
| asyncFunction(function(){ | |
| data.key2 += 0x333; | |
| end(); | |
| }); | |
| asyncFunction(function(){ | |
| data.key2 += 0x444; | |
| end(); | |
| }); | |
| var end = function(){ | |
| if(++count === 2) | |
| console.log("Fin") | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment