Skip to content

Instantly share code, notes, and snippets.

@crodjer
Created March 27, 2013 05:26
Show Gist options
  • Save crodjer/5251904 to your computer and use it in GitHub Desktop.
Save crodjer/5251904 to your computer and use it in GitHub Desktop.
Promises in PouchDB
// With the existing Pouch(dbname, callback) api
db = Pouch('adapter://identifier');
data = {
dummy: true
};
promise = db.post(data); // As soon as the db is available, post this data.
// For a callback, it can behave like promises
promise.then(function (response) {
// Do something with the object.
}, function (err, response){
// Notify somebody that it failed.
});
// All other methods which take callbacks follow the same pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment