Skip to content

Instantly share code, notes, and snippets.

@iendjinn
Created February 17, 2017 12:35
Show Gist options
  • Save iendjinn/62e812cefff5c69a3aa4440e257d93d8 to your computer and use it in GitHub Desktop.
Save iendjinn/62e812cefff5c69a3aa4440e257d93d8 to your computer and use it in GitHub Desktop.
// estimator.js
module.exports = (function() {
var getData = function(id, cb) {
api.getData(id, this.state.filter, (err, response) => {
if (err) {
cb(err);
} else {
cb(null, response.data);
}
});
}
function estimator(initial) {
this.state = initial;
this.getData = getData;
}
return estimator;
}());
// Databot.js
var Promise = require("bluebird");
var Estimator = Promise.promisifyAll(require("./estimator.js"));
var estimator = new Estimator(initial);
estimator.getDataAsync(id).then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment