Skip to content

Instantly share code, notes, and snippets.

@L8D
Forked from Hanspagh/async.js
Last active August 27, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L8D/5971a824c876da534459 to your computer and use it in GitHub Desktop.
Save L8D/5971a824c876da534459 to your computer and use it in GitHub Desktop.
function findOrCreate(id) {
return Promise.try(function() {
return db.find(id);
}).then(function(result) {
if (result == null) {
return db.create(id);
} else {
return result;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment