Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "fastq", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Fast, in memory work queue", | ||
@@ -5,0 +5,0 @@ "main": "queue.js", |
21
queue.js
'use strict' | ||
function fastqueue (worker, limit) { | ||
var cacheHead = new Task(release) | ||
function fastqueue (context, worker, limit) { | ||
if (typeof context === 'function') { | ||
limit = worker | ||
worker = context | ||
context = null | ||
} | ||
var cacheHead = new Task(context, release) | ||
var cacheTail = cacheHead | ||
@@ -30,3 +37,3 @@ var queueHead = null | ||
limit-- | ||
worker(current.value, current.worked) | ||
worker.call(context, current.value, current.worked) | ||
} | ||
@@ -41,3 +48,3 @@ } | ||
} else { | ||
cacheHead = new Task(release) | ||
cacheHead = new Task(context, release) | ||
cacheTail = cacheHead | ||
@@ -61,3 +68,3 @@ } | ||
next.next = null | ||
worker(next.value, next.worked) | ||
worker.call(context, next.value, next.worked) | ||
} else { | ||
@@ -71,3 +78,3 @@ limit++ | ||
function Task (release) { | ||
function Task (context, release) { | ||
this.value = null | ||
@@ -83,3 +90,3 @@ this.callback = noop | ||
self.callback = noop | ||
callback(err, result) | ||
callback.call(context, err, result) | ||
release(self) | ||
@@ -86,0 +93,0 @@ } |
@@ -41,4 +41,24 @@ # fastq [![build status](https://secure.travis-ci.org/mcollina/fastq.png)](http://travis-ci.org/mcollina/fastq) | ||
### Setting this | ||
```js | ||
'use strict' | ||
var that = { hello: 'world' } | ||
var queue = require('fastq')(that, worker, 1) | ||
queue.push(42, function (err, result) { | ||
if (err) { throw err } | ||
console.log(this) | ||
console.log('the result is', result) | ||
}) | ||
function worker (arg, cb) { | ||
console.log(this) | ||
cb(null, 42 * 2) | ||
} | ||
``` | ||
## License | ||
ISC |
17
test.js
@@ -89,1 +89,18 @@ 'use strict' | ||
}) | ||
test('set this', function (t) { | ||
t.plan(3) | ||
var that = {} | ||
var queue = buildQueue(that, worker, 1) | ||
queue.push(42, function (err, result) { | ||
t.error(err, 'no error') | ||
t.equal(this, that, 'this matches') | ||
}) | ||
function worker (arg, cb) { | ||
t.equal(this, that, 'this matches') | ||
cb(null, true) | ||
} | ||
}) |
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
8106
205
64