Created
October 24, 2014 07:34
-
-
Save twn39/b2ed92fa8d023ec586f5 to your computer and use it in GitHub Desktop.
Promise [bluebird]
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
| var Promise = require('bluebird'); | |
| var fs = require('fs'); | |
| function readFile(path) { | |
| var file = new Promise(function(resolve, reject) { | |
| fs.readFile(path, 'utf8', function(err, data) { | |
| if(err) { | |
| reject(err); | |
| } else { | |
| resolve(data); | |
| } | |
| }); | |
| }); | |
| return file; | |
| } | |
| var path = './package.json'; | |
| readFile(path).then(function(data) { | |
| console.log(data); | |
| }).catch(function(err) { | |
| console.log(err); | |
| }).done(function(){ | |
| console.log('done'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment