promisify-k

0.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i promisify-k

Weekly Downloads

4

Version

0.0.2

License

none

Last publish

Collaborators

  • impero
  • jacopodaeli