pangako

0.0.1 • Public • Published

pangako

A bare bones Javascript Promises/A+ spec implementation.

This implementation passes the Promises/A+ Compliance Test Suite.

Usage

This example will create a deferred object which contains a promise and two callbacks, resolve and reject, which can be called to settle the promise. A timeout is then set to resolve the promise after 10 seconds. then is called on the promise to set a callback which will execute when the promise is fulfilled.

Using pangako.defer


const pangako = require('pangako');

// create a deferred and set a timeout to resolve the deferred
var deferred = pangako.defer();
setTimeout(function() {
  deferred.resolve("I'm now resolved!");
}, 10000);

// waits for the promise to get resolved and then prints the value
deferred.promise.then(function(value) {
  console.log(value);
});

Using pangako.Promise


const Promise = require('pangako').Promise;

// construct a new Promise and does some work and resolves itself
var promise = new Promise(function(resolve, reject) {
  setTimeout(function() {
    resolve("I'm now resolved!");
  }, 10000);
});

promise.then(function(value) {
  console.log(value);
});

Testing - Running the compliance test suite

To test the installation, run:

Run:


npm test

Results should be:


...
  872 passing (13s)

Readme

Keywords

Package Sidebar

Install

npm i pangako

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • melmerp