Created
June 13, 2016 19:08
-
-
Save ajcrites/10ec9c1f4beca49bf4903d06af8e0940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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