Skip to content

Instantly share code, notes, and snippets.

@superlou
Created February 13, 2012 01:52
Show Gist options
  • Save superlou/1812642 to your computer and use it in GitHub Desktop.
Save superlou/1812642 to your computer and use it in GitHub Desktop.
Loop until unique?
var name_is_unique = false;
var name;
while (!name_is_unique) {
name = namer.generate();
var waiting_on_db = true;
User.find({name: name}, function(err,docs) {
if (docs.count > 0) {
name_is_unique = true;
}
waiting_on_db = false;
});
while (waiting_on_db) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment