0.0.2 • Published 9 years ago

promisify-k v0.0.2

Weekly downloads
10
License
-
Repository
github
Last release
9 years ago

Introduction

Simple promisify module for Node.

Chained promise are supported.

Methods

  • Promise.prototype.then(onSuccess, onRejected): Appends success and rejection handlers to the promise, and returns a new promise resolving to the return value of the called handler.

  • Promise.prototype.catch(onRejected): Appends a rejection handler callback to the promise, and returns a new promise resolving to the return value of the callback if it is called, or to its original success value if the promise is instead fulfilled.

Usage

Code:

// myapp.js

var K = require('promisify-k').K;
var promise = new K(function(success, rejected) {
  console.log('Promise is working!');
  success(1);
});

promise
.then(function(num) {
  console.log(num);
  return num + 1;
})
.then(function(num) {
  console.log(num);
})
.catch(function(err) {
  console.error(err);
});

Output:

$ node myapp.js
Promise is working!
1
2