Created
October 27, 2016 06:09
-
-
Save meredian/8b05a08ca4f0daab8a78f48e51fe2b34 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
function asynchronousIterator(limit, f1) { | |
var sum = 0; | |
var limit = 3; | |
fAsync(limit, function(res) { | |
console.log("Intermediate result", res); | |
sum += res; | |
limit--; | |
if(limit === 0){ | |
f1(sum); | |
} | |
}) | |
} | |
function fAsync(x, f2) { | |
var result = x * x; | |
setTimeout(function(){ | |
f2(result); | |
}, Math.random() * 100); | |
x--; | |
if(x > 0){ | |
fAsync(x,f2); | |
} | |
} | |
asynchronousIterator(5, function(a){ | |
console.log(a); | |
}); |
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
➜ i3bitrix-test git:(master) ✗ node synh_vs_an.js | |
Intermediate result 4 | |
Intermediate result 9 | |
Intermediate result 1 | |
14 | |
➜ i3bitrix-test git:(master) ✗ node synh_vs_an.js | |
Intermediate result 1 | |
Intermediate result 4 | |
Intermediate result 9 | |
14 | |
➜ i3bitrix-test git:(master) ✗ node synh_vs_an.js | |
Intermediate result 9 | |
Intermediate result 1 | |
Intermediate result 4 | |
14 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment