Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
var CorePromise = Promise; // just the native thing
var adapter = {
/**
* resolved - Create a resolved promise.
* @param {any} value
* @return {Promise}
*/
resolved : function(value) {
return CorePromise.resolve(value);
},
/**
* rejected - Create a rejected promise
* @param {} value
* @return {Promise}
*/
rejected : function(value) {
return CorePromise.reject(value);
},
deferred: function() {
var result,
_fulfill,
_reject;
result = new CorePromise(function(fulfill, reject) {
_fulfill = fulfill;
_reject = reject;
});
return {
promise: result,
resolve: function(v) {
try {
_fulfill(v);
} catch (e1) {
console.log("ERROR:", e1);
}
},
reject: function(e) {
try {
_reject(e);
} catch (e2) {
console.log("ERROR:", e2);
}
}
};
}
};
tests = require("promises-aplus-tests");
describe("Promises/A+ Tests", function () {
for (var i = 0; i < 10; i++) {
tests.mocha(adapter);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment