Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise consistency #74

Open
besarthoxhaj opened this issue Mar 22, 2016 · 1 comment
Open

Promise consistency #74

besarthoxhaj opened this issue Mar 22, 2016 · 1 comment

Comments

@besarthoxhaj
Copy link

Hi all!:)

Really like the db helpers, that's a nice way to decouple functionality and provide just an high level function to be used around the code while hiding implementation.

Noticed however that you use a callback pattern in some places and promises in others. In case you don't know how to create a promise pattern here is an example:

// normal callback pattern
function getItem (id,callback) {

  // some async call to db
  if (err) {
    callback(err,null);
  } else {
    callback(null,{id:5,name:'Bes'});
  }
}
// normal promise pattern
const Promise = require('bluebird');

function getItem (id) {

  return new Promise(function (resolve, reject) {
    // some async call to db
    if (err) {
      reject(err);
    } else {
      resolve({id:5,name:'Bes'});
    }
  });
}

Hope that helps.

@franzmoro
Copy link
Member

thanks @besarthoxhaj !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants