Created
July 31, 2015 10:10
-
-
Save mosfet1kg/64e7280b25b014793c6f to your computer and use it in GitHub Desktop.
Q + Closure
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
| var Q = require('q'); | |
| var funcs = []; | |
| for (var i = 0; i < 3; i++) { | |
| funcs.push((function(m){ | |
| return function() { | |
| var d = Q.defer(); | |
| console.log("My value: " + m); | |
| d.resolve(); | |
| return d.promise; | |
| }; | |
| })(i)); | |
| } | |
| var result = Q(); | |
| funcs.forEach(function(f){ | |
| result = result.then(f); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment