Created
April 17, 2013 09:33
-
-
Save serby/5403020 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
| var q = [] | |
| function (req, res) { | |
| q.push(function (cb) { | |
| resize(req.body, function(error, complete) { | |
| res.send(complete) | |
| cb() | |
| }) | |
| }) | |
| } | |
| function next() { | |
| process.nextTick(function () { | |
| if (q.length > 0) { | |
| var work = q.pop() | |
| work(next) | |
| } | |
| }) | |
| } | |
| next() | |
| next() | |
| next() | |
| next() | |
| /// | |
| var q = async.queue(function (fn, callback) { | |
| fn(callback) | |
| }, 6) | |
| // assign a callback | |
| q.drain = function() { | |
| console.log('all items have been processed'); | |
| } | |
| function (req, res) { | |
| q.push(function (cb) { | |
| resize(req.body, function(error, complete) { | |
| res.send(complete) | |
| cb() | |
| }) | |
| }) | |
| } | |
| q.push({name: 'foo'}, function (err) { | |
| console.log('finished processing foo'); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment