Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 13, 2016 19:08
Show Gist options
  • Select an option

  • Save ajcrites/10ec9c1f4beca49bf4903d06af8e0940 to your computer and use it in GitHub Desktop.

Select an option

Save ajcrites/10ec9c1f4beca49bf4903d06af8e0940 to your computer and use it in GitHub Desktop.
const Promise = require("bluebird");
const docClient = {
put(x, cb) {
setTimeout(() => {
if (1 == x) {
cb(null, "good");
}
else {
cb(new Error("bad"));
}
}, 100);
}
};
const promisedLib = Promise.promisifyAll(lib);
lib.put(1, (err, result) => console.log(result));
lib.put(0, (err, result) => console.log(err.message));
lib.putAsync(1)
.then(result => console.log("\n===promises===\n\n", result))
.then(() => lib.putAsync(1))
.then(result => console.log(result))
.then(() => lib.putAsync(0))
.catch(err => console.error(err.message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment