Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A standalone javascript promise framework which works on the web and CommonJS environments
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
tests
README.md

README.md

PromiseJS

PromiseJS is a standalone JavaScript framework which helps you subscribe to an async operation which can notify you upon its completion. It works on the web as well as any CommonJS environments. It has no dependencies on any other frameworks.

A simple example

function doAsync(){
  var d = new PromiseJS.Deferred();

  setTimeout(function(){
    d.resolve();
  }, 1000);

  return d.promise;
}

var promise = doAsync();

promise
  .success(function(){
    alert("Succeeded");
  })
  .fail(function(){
    alert("Failed");
  });

Use when(funcs) to join a list of promises and get notified when all of them complete

var promise = PromiseJS.when(promise1, promise2, promise3, promise4); //  You can also pass an array of promises here

promise.then(function(promises){  //  An array of completed promises are passed as argument to the callback
  promises.forEach(function(p){
    if( promise.isResolved() ){
      alert( p.value() ); //  value() returns the result or error attached with the promise
    }
  });
})

Use chain(funcs) to call a list of deferred functions sequentially

var promise = PromiseJS.chain(func1, func2, func3, func4);  //  You can also pass an array of functions here

promise.then(function(promises){  //  An array of completed promises are passed as argument to the callback
  promises.forEach(function(p){
    if( promise.isResolved() ){
      alert( p.value() ); //  value() returns the result or error attached with the promise
    }
  });
});

Use isPending(), isResolved() and isRejected() on a promise to check the status

Checkout the complete documentation here.

Something went wrong with that request. Please try again.