Skip to content

Commit

Permalink
Promises/A+ compliance (fixes #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilclass committed Jan 18, 2013
1 parent 881cf76 commit 0f7ac4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "http://github.com/nilclass/promising",
"devDependencies": {
"promise-tests": "*"
"promises-aplus-tests": "*"
},
"scripts": {
"test": "node test/run.js"
Expand Down
17 changes: 8 additions & 9 deletions src/promising.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions test/run.js
Original file line number Diff line number Diff line change
@@ -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.