Permalink
Browse files

Promises/A+ compliance (fixes #2)

  • Loading branch information...
1 parent 881cf76 commit 0f7ac4af0d2d0768dac7fc4a6b197011e19f572b @nilclass committed Jan 18, 2013
Showing with 15 additions and 17 deletions.
  1. +1 −1 README.md
  2. +2 −2 package.json
  3. +8 −9 src/promising.js
  4. +4 −5 test/run.js
View
@@ -1,5 +1,5 @@
-Implementation of Promises/A and some other stuff (always-async, returning-a-promise).
+Implementation of [Promises/A](http://promises-aplus.github.com/promises-spec/)
[![Build Status](https://secure.travis-ci.org/nilclass/promising.png)](http://travis-ci.org/nilclass/promising)
View
@@ -1,6 +1,6 @@
{
"name": "promising",
- "version": "0.0.3",
+ "version": "0.0.4",
"private": false,
"author": "Niklas Cathor <nil.niklas@gmail.com>",
"license": "MIT",
@@ -10,7 +10,7 @@
},
"homepage": "http://github.com/nilclass/promising",
"devDependencies": {
- "promise-tests": "*"
+ "promises-aplus-tests": "*"
},
"scripts": {
"test": "node test/run.js"
View
@@ -28,12 +28,10 @@ function getPromise() {
consumer.promise.reject(exc);
return;
}
- if(typeof(ret) !== 'undefined') {
- if(typeof(ret.then) === 'function') {
- ret.then(consumer.promise.fulfill, consumer.promise.reject);
- } else {
- consumer.promise.fulfill(ret);
- }
+ if(ret && typeof(ret.then) === 'function') {
+ ret.then(consumer.promise.fulfill, consumer.promise.reject);
+ } else {
+ consumer.promise.fulfill(ret);
}
} else {
consumer.promise.reject.apply(null, result);
@@ -43,7 +41,8 @@ function getPromise() {
function resolve(succ, res) {
if(result) {
- throw new Error("Can't resolve promise, already resolved!");
+ console.log("WARNING: Can't resolve promise, already resolved!");
+ return;
}
success = succ;
result = Array.prototype.slice.call(res);
@@ -63,8 +62,8 @@ function getPromise() {
then: function(fulfilled, rejected) {
var consumer = {
- fulfilled: fulfilled,
- rejected: rejected,
+ fulfilled: typeof(fulfilled) === 'function' ? fulfilled : undefined,
+ rejected: typeof(rejected) === 'function' ? rejected : undefined,
promise: getPromise()
};
if(result) {
View
@@ -1,8 +1,7 @@
-var promiseTests = require('promise-tests');
+var promiseTests = require('promises-aplus-tests');
var adapter = require('./promising-adapter');
-promiseTests(adapter, ['promises-a', 'always-async', 'returning-a-promise'],
- function() {
- console.log("Tests all done.");
- });
+promiseTests(adapter, function() {
+ console.log("Tests all done.");
+});

0 comments on commit 0f7ac4a

Please sign in to comment.