Last active
December 25, 2015 08:28
-
-
Save pH200/6946429 to your computer and use it in GitHub Desktop.
coke concurrent promises
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
find_all_user_emails : function ( count, next ){ | |
var i = Math.ceil( count / 10000 ); | |
var skip = 0; | |
var promises = []; | |
for( ; i-- ; ){ | |
promises.push( User. | |
find({ is_verified : true }) | |
lean(). | |
select( 'email' ). | |
limit( 10000 ). | |
skip( skip ). | |
execQ()); | |
skip += 10000; | |
} | |
Q.all( promises ). | |
then( function ( many_users ){ | |
return Array.prototype.concat([], many_users ); | |
}). | |
nodeify( next ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment