Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

q

Package Overview
Dependencies
Maintainers
0
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

q - npm Package Compare versions

Comparing version 0.4.4 to 0.5.0

test/join.js

2

package.json
{
"name": "q",
"description": "A library for promises (CommonJS/Promises/A,B,D)",
"version": "0.4.4",
"version": "0.5.0",
"homepage": "http://github.com/kriskowal/q/",

@@ -6,0 +6,0 @@ "author": "Kris Kowal <kris@cixar.com> (http://github.com/kriskowal/)",

@@ -63,2 +63,8 @@ // vim:ts=4:sts=4:sw=4:

}
var reduce = Array.prototype.reduce || function (callback, basis) {
for (var i = 0, ii = this.length; i < ii; i++) {
basis = callback(basis, this[i], i);
}
return basis;
};

@@ -177,4 +183,28 @@ var print = typeof console === "undefined" ? identity : function (message) {

Promise.prototype.wait = function () {
return reduce.call(arguments, function (self, next) {
return when(next, function () {
return self;
});
}, this);
};
Promise.prototype.join = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
var callback = args.pop();
return reduce.call(args, function (done, next, i) {
return when(next, function (next) {
return when(done, function () {
args[i] = next;
});
});
}, undefined)
.then(function () {
return callback.apply(undefined, args);
});
};
Promise.prototype.end = function () {
when(this, undefined, error);
end(this);
};

@@ -189,4 +219,4 @@

return when(this, undefined, function (reason) {
report(error);
report(reason);
print(error && error.stack || error);
print(reason && reason.stack || reason);
return reject(reason);

@@ -283,4 +313,4 @@ });

if (op !== "when") {
return Q.when(object, function (value) {
return Q.ref(value).promiseSend.apply(null, arguments);
return when(object, function (value) {
return ref(value).promiseSend.apply(null, arguments);
});

@@ -539,35 +569,14 @@ } else {

/**
* Throws an error with the given reason.
* Terminates a chain of promises, forcing rejections to be
* thrown as exceptions.
*/
exports.error = error;
function error(reason) {
if (typeof process !== "undefined") {
report(reason);
process.exit(reason ? reason.exit || 1 : 1);
} else {
report(reason);
throw reason;
}
};
/**
* Reports an error and returns it as a rejection.
*
* Q.when(function () {
* if (failure) {
* throw new Error();
* } else {
* return success;
* }
* })
* // report the error
* .then(null, Q.report)
* .then(function (success) {
* // carry on if no failure
* });
*/
exports.report = report;
function report(reason) {
print(reason && reason.stack || reason);
return reject(reason);
exports.end = end;
function end(promise) {
when(promise, undefined, function (error) {
// forward to a future turn so that ``when``
// does not catch it and turn it into a rejection.
enqueue(function () {
throw error;
});
});
}

@@ -574,0 +583,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc