Skip to content

Commit

Permalink
feat: add _kareemIgnore re: Automattic/mongoose#4836
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Jan 2, 2017
1 parent f9e9a09 commit 7957771
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions index.js
Expand Up @@ -130,9 +130,14 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {

var next = function() {
var post = posts[currentPost];
var numArgs = 0;
var argLength = args.length;
for (var i = 0; i < argLength; ++i) {
numArgs += args[i] && args[i]._kareemIgnore ? 0 : 1;
}

if (firstError) {
if (post.length === args.length + 2) {
if (post.length === numArgs + 2) {
post.apply(context, [firstError].concat(args).concat(function(error) {
if (error) {
firstError = error;
Expand All @@ -149,14 +154,14 @@ Kareem.prototype.execPost = function(name, context, args, options, callback) {
next();
}
} else {
if (post.length === args.length + 2) {
if (post.length === numArgs + 2) {
// Skip error handlers if no error
if (++currentPost >= numPosts) {
return callback.apply(null, [null].concat(args));
}
return next();
}
if (post.length === args.length + 1) {
if (post.length === numArgs + 1) {
post.apply(context, args.concat(function(error) {
if (error) {
firstError = error;
Expand Down

0 comments on commit 7957771

Please sign in to comment.