0.4.3 • Published 7 years ago

promise-from v0.4.3

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

Promise From

This is very simple wrapper to adapt NodeJS style API to ES6 Promise. The module requires the Proxy feature provided by ES6.

Features

  • Very simple to use
  • Easy to chain async calls
  • Support expect-like syntax to handle events
  • Build-in Promise finally implementation
  • Depend on Node.JS only

Install

npm install promise-from

Quick Start

const fs = require('fs');
const promiseFrom = require('promise-from');

promiseFrom(fs.createWriteStream('hello'))
.expect('open')
.write('hello')
.chain(function() {
  console.info('this will be called and chained');
})
.chain(function(done) {
  console.info('this will be called and will continue to then() after done() is called');
  setTimeout(done, 1000);
})
.write('promise')
.then(function() {
  console.log('all operations are successful.');
})
.catch(function(err) {
  console.log('oops, something went wrong!');
  console.error(err);
})
.finally(function() {
  console.log('This will always be called.');
});

API

All function calls to the proxied object are recorded and executed after one of then(), catch() or finally() are called.

expect(good, bad='error')

expect good event to resolve promise and bad event to reject.

finally(onFinally)

called at the end of async operations whether to do clean up or if you don't care the result.

License

MIT

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago