Comparing version 0.2.1 to 0.2.2
@@ -693,2 +693,25 @@ /*global setImmediate: false, setTimeout: false, console: false */ | ||
async.queue = function (worker, concurrency) { | ||
function _insert(q, data, pos, callback) { | ||
if(data.constructor !== Array) { | ||
data = [data]; | ||
} | ||
_forEach(data, function(task) { | ||
var item = { | ||
data: task, | ||
callback: typeof callback === 'function' ? callback : null | ||
}; | ||
if (pos) { | ||
q.tasks.unshift(item); | ||
} else { | ||
q.tasks.push(item); | ||
} | ||
if (q.saturated && q.tasks.length === concurrency) { | ||
q.saturated(); | ||
} | ||
async.nextTick(q.process); | ||
}); | ||
} | ||
var workers = 0; | ||
@@ -702,16 +725,7 @@ var q = { | ||
push: function (data, callback) { | ||
if(data.constructor !== Array) { | ||
data = [data]; | ||
} | ||
_forEach(data, function(task) { | ||
q.tasks.push({ | ||
data: task, | ||
callback: typeof callback === 'function' ? callback : null | ||
}); | ||
if (q.saturated && q.tasks.length === concurrency) { | ||
q.saturated(); | ||
} | ||
async.nextTick(q.process); | ||
}); | ||
_insert(q, data, false, callback); | ||
}, | ||
unshift: function (data, callback) { | ||
_insert(q, data, true, callback); | ||
}, | ||
process: function () { | ||
@@ -718,0 +732,0 @@ if (workers < q.concurrency && q.tasks.length) { |
@@ -6,3 +6,3 @@ { | ||
"author": "Caolan McMahon", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"repository" : { | ||
@@ -25,3 +25,11 @@ "type" : "git", | ||
"nodelint": ">0.0.0" | ||
}, | ||
"jam": { | ||
"main": "lib/async.js", | ||
"include": [ | ||
"lib/async.js", | ||
"README.md", | ||
"LICENSE" | ||
] | ||
} | ||
} |
@@ -809,2 +809,3 @@ # Async.js | ||
instead of a single task, an array of tasks can be submitted. the respective callback is used for every task in the list. | ||
* unshift(task, [callback]) - add a new task to the front of the queue. | ||
* saturated - a callback that is called when the queue length hits the concurrency and further tasks will be queued | ||
@@ -844,2 +845,8 @@ * empty - a callback that is called when the last item from the queue is given to a worker | ||
}); | ||
// add some items to the front of the queue | ||
q.unshift({name: 'bar'}, function (err) { | ||
console.log('finished processing bar'); | ||
}); | ||
``` | ||
@@ -846,0 +853,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67537
865
1246