JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 30643
  • Score
    100M100P100Q150903F
  • License MIT

ES6 Promise Shim

Package Exports

  • promish

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (promish) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Promish

     SH
      I
P R O M

The Promish module creates a wrapper around the EcmaScript 6 Promise class. It adds some of the useful features found in many of the other popular promise libraries such as Q and Bluebird. It is designed to be interchangeable with the ES6 Promise as its interface is a superset of the Promise class.

Installation

npm install promish

New Features!

Backlog

  • TBD

Contents

Interface

Include

var Promish = require('promish');

Instantiation

Typical use - construct with handler function

var promise = new Promish(function(resolve, reject) {
  // do something async
});

3rd Party Wrapper Mode

var promise = new Promish(Q());

Value Wrapper Mode

var promise = new Promish('Resolve Value');

Error Wrapper Mode

var promise = new Promish(new Error('This promise is rejected'));

Then

// typical use
promise
  .then(function(value) {
    // something async has completed with a value
    // here you can return a resolve value,
    // return a new Promish or throw an error (handled as rejection)
  });
  
// with onRejected...
promise.then(
  function(value) {
  },
  function(error) {
  });

Catch

// catch all
promise
  .catch(function(error) {
    // Something async has failed with an error.
    // Just like with then(), you can return a resolve value,
    // return a new Promish or throw a new error (handled as rejection)
    // You can also 'rethrow' the error by returning a new Promish with the error
  });

Defer

For compatability with the old Promise.defer() pattern...

function readAFile(filename) {
  var deferred = Promish.defer();
  
  fs.readFile(filename, function(error, data) {
    if (error) {
      deferred.reject(error);
    } else {
      deferred.resolve(data);
    }
  });
  
  return deferred.promise;
}

Spread

Promish.all(getPromish1(), getPromish2(), getPromish3())
  .spread(function(value1, value2, value3) {
    // use values...
  });

Known Issues

  • TBD

Release History

Version Changes
0.0.1
  • Initial Version
0.0.2