-
-
Save clarkf/1681368 to your computer and use it in GitHub Desktop.
What did I do here?
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'), | |
| guid = 1; | |
| function randomDefer() { | |
| var defer = q.defer(), id = guid++; | |
| console.log("sending %d", id); | |
| setTimeout(function () { | |
| console.log("resolving %d", id); | |
| defer.resolve('hi'); | |
| }, Math.round(Math.random() * 3000)); | |
| return defer.promise; | |
| } | |
| var qs = [randomDefer(), randomDefer(), randomDefer(), randomDefer(), randomDefer()]; | |
| q.all(qs).spread(function () { | |
| console.log('value handler'); | |
| console.log(arguments); | |
| }); |
Author
Author
Ugh... Looks like I needed to return defer.promise. New output:
sending 1
sending 2
sending 3
sending 4
sending 5
resolving 1
resolving 3
resolving 5
resolving 4
resolving 2
value handler
{ '0': 'hi', '1': 'hi', '2': 'hi', '3': 'hi', '4': 'hi' }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output (doesn't matter whether I use
.spreador.then):