JSPM

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

A simple A+ promises implementation

Package Exports

  • fidelity

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 (fidelity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Fidelity

A simple promises-aplus implementation. Faster than Q, slower than Bluebird. Simpler and smaller than both.

Installing

npm install fidelity

API Documentation

The API is pretty simple, and it's lightly documented here.

Usage

A fidelity promise takes a function as an argument. This function accepts a resolve and a reject object. Suppose we have a function f() that takes some time to complete asynchronously. We can call this function using a promise.

var Fidelity = require('fidelity');

Fidelity.promise( (resolve, reject) => {
  someAsyncFunction((result, err) => {
    if (err) {
      reject(err);
    } else {
      resolve(result);
    }
  });
}).then( (val) => {
  // Do something with the result.
});

The promise object returned from promise() has a function, then(). This takes two function arguments. The first is called with the return value (if any) of the promise function if it is successfully fulfilled. The second function is called in the event of an error.

p.then( (result) => {
  console.log('sucessful result ', result);
}, (err) => {
  console.error('whoops!', err);
});

Testing

This module passes all of the tests in the Promises/A+ Compliance Test Suite. To run the full suite of the Promises/A+ spec, just npm test from the command line.