Created
December 2, 2011 21:18
-
-
Save peutetre/1424872 to your computer and use it in GitHub Desktop.
Stupid q.js test (serial join)
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src="q.js"></script> | |
| <script> | |
| function add(millis, answer, msg) { | |
| const defer = Q.defer(); | |
| setTimeout(function() { | |
| if (answer instanceof Array) { | |
| answer.push(msg); | |
| } | |
| else { | |
| answer = []; | |
| answer.push(msg); | |
| } | |
| console.log(msg); | |
| defer.resolve(answer); | |
| }, millis); | |
| return defer.promise; | |
| } | |
| function test1(done) { | |
| [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].forEach(function (value) { | |
| done = Q.when(done, function (answer) { | |
| return add(1000, answer, value); | |
| }); | |
| }); | |
| return done; | |
| } | |
| function doit() { | |
| Q.when( | |
| test1(), | |
| function (answer) { | |
| console.log(answer); | |
| } | |
| ); | |
| } | |
| </script> | |
| </head> | |
| <body onload="doit()"></body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment