Skip to content

melmerp/pangako

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pangako

A bare bones Javascript Promises/A+ spec implementation.

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

Installation

npm install pangako

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)

About

A bare bones Javascript Promises/A+ implementation.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published