Comparing version 1.0.1 to 1.0.2
@@ -5,3 +5,3 @@ { | ||
"description": "queue up async function calls without the overhead", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"keywords": [], | ||
@@ -8,0 +8,0 @@ "dependencies": {}, |
1.0.2 / 2015-03-19 | ||
================== | ||
* cleanup after timeouts | ||
1.0.1 / 2015-03-19 | ||
@@ -3,0 +8,0 @@ ================== |
25
index.js
@@ -28,3 +28,5 @@ /** | ||
var pending = 1; | ||
var tids = {}; | ||
var jobs = []; | ||
var id = 0; | ||
@@ -42,6 +44,7 @@ return function() { | ||
var ctx = this; | ||
id++; | ||
// remove "on end" function if there is one | ||
end = end ? args.pop() : noop; | ||
jobs.push([ctx, args.concat(once(done))]); | ||
jobs.push([id, ctx, args.concat(once(done(id)))]); | ||
return next(); | ||
@@ -54,4 +57,5 @@ | ||
var ctx = job[0]; | ||
var args = job[1]; | ||
var id = job[0] | ||
var ctx = job[1]; | ||
var args = job[2]; | ||
var finish = args[args.length - 1]; | ||
@@ -63,3 +67,3 @@ | ||
if (timeout) { | ||
setTimeout(function() { | ||
tids[id] = setTimeout(function() { | ||
finish(new Error('job timed out')) | ||
@@ -70,9 +74,12 @@ }, timeout); | ||
// call the fn | ||
return fn.apply(job[0], job[1]); | ||
return fn.apply(job[1], job[2]); | ||
} | ||
function done() { | ||
pending--; | ||
next(); | ||
return end.apply(this, arguments); | ||
function done(id) { | ||
return function _done() { | ||
clearTimeout(tids[id]); | ||
pending--; | ||
next(); | ||
return end.apply(this, arguments); | ||
} | ||
} | ||
@@ -79,0 +86,0 @@ } |
{ | ||
"name": "enqueue", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "queue up function calls", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -29,3 +29,4 @@ | ||
concurrency: 2, | ||
timeout: 1000 | ||
timeout: 1000, | ||
limit: 10 | ||
}; | ||
@@ -53,3 +54,3 @@ | ||
- `limit` (default: `Infinity`): limit how many jobs can be queued up at any given time. | ||
will return an `Error` if the limit has been reached. | ||
`queue` will return an `Error` if the limit has been reached. | ||
@@ -56,0 +57,0 @@ ### `queue(args..., [end])` |
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
44985
590
90