promiseful
v0.1.3
Published
Useful patterns with Promise functions
Downloads
33
Maintainers
Readme
promiseful
Useful patterns with Promise functions
Installation
$ npm install promiseful --save
To use in the browser, download the library from dist folder.
Usage
node.js
promiseful uses native ES2015 Promise
.
To use non-native, 3rd-party Promise
libraries, like bluebird or Promise polyfill, call promiseful.promise()
with the Promise
object, before using the API.
e.g.:
var Promise = require('bluebird');
// var Promise = require('es6-promise');
// var Promise = require('pinkie-promise');
var promiseful = require('promiseful');
promiseful.promise(Promise);
See example
Browser
promiseful uses native ES2015 Promise
.
To use non-native, 3rd-party Promise
libraries, like bluebird or Promise polyfill, include the library, before including promiseful.
e.g.:
<script src="https://cdn.jsdelivr.net/bluebird/latest/bluebird.min.js"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.0/es6-promise.min.js"></script> -->
<script src="promiseful.js"></script>
See example
API
A promiseful function is a function that returns a Promise
.
e.g.:
function readPasswd() {
return new Promise((resolve, reject) => {
fs.readFile('/etc/passwd', (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
The API works with promiseful functions. Do not pass Promise objects.
Methods follow pattern, similar to the excellent caolan/async library.