Home

Awesome

puremise.js

Yet another purely functional Promise Monad implementation. I tried to implement it obeying functional programming rules.

Implementation Details in Turkish

Examples

x = Promise(function () {
  console.log("x resolved");
})

x.success(function () {
  console.log("x resolved again..");
});

x.success(function () {
  console.log("x resolved again and again..");
});

y = Promise().success(function () {
  console.log("y resolved");
});

y.fail(function () {
  console.log("y rejected");
});

When([x, y]).success(function () {
  console.log("x and y all resolved");
});

Resolve the promises:

x.resolve(); //=> "x resolved", "x resolved again..", "x resolved again and again.."

y.resolve(); //=> "y resolved", "x and y all resolved"

And it can be rejected, too:

When([x, y]).success(function () {
  console.log("x and y all resolved");
}).fail(function () {
  console.log("something rejected!");
});

y.reject(); //=> "something rejected!"

Async Usage

function defer() {
  var deferred = Promise();
  setTimeout(deferred.resolve, 1000);
  return deferred;
}

defer().success(function () {
  console.log("this will be resolved after 1 sec.!");
});

// after 1 sec: => "this will be resolved after 1 sec.!"

License

MIT License