Skip to content

waka/js-promise-simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-promise-simple

The simple implementation of CommonJS Promises/A.

Usage

From node.js

var Promise = require('promise-simple');

Promise.defer()
.next(function() {
  return "ok"; // call after 1000ms.
}, 1000)
.next(function(res) {
  console.log(res); // call after 2000ms, and res is "ok"
}, 2000);

From browser side javascript

<script src="/path/to/promise-simple.js"></script>
var asyncFunc1 = function() {
  var d = Promise.defer();
  setTimeout(function() {
    d.resolve("first");
  }, 1000);
  return d;
};
var asyncFunc2 = function() {
  var d = Promise.defer();
  setTimeout(function() {
    d.resolve("second");
  }, 1000);
  return d;
};

Promise.when(asyncFunc1, asyncFunc2).then(function(results) {
  console.log(results[0]); // "first"
  console.log(results[1]); // "second"
});

Testing

Using mocha from Node.js.

$npm test

or open "test/browser/promise-simple_test.html" by some browser.

About

Simple implementation of CommonJS Promises/A

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published