Skip to content

Instantly share code, notes, and snippets.

@pH200
Last active December 25, 2015 08:28
Show Gist options
  • Save pH200/6946429 to your computer and use it in GitHub Desktop.
Save pH200/6946429 to your computer and use it in GitHub Desktop.
coke concurrent promises
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