Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
nullivex committed Oct 16, 2014
1 parent e74e61e commit 27917d9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 39 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
promiseq
PromiseQ [![Build Status](https://travis-ci.org/snailjs/promiseq.png?branch=master)](https://travis-ci.org/snailjs/promiseq)
========

Promise queue for node.js
Expand All @@ -22,5 +22,19 @@ var queue = new PromiseQueue(workerCount)

//make a job
var job = function(){
return
queue.push
return new P(function(resolve,reject){
process.nextTick(resolve)
})
}

//add a single job
queue.push(job).then(function(){console.log('Job complete'}))

//close the queue and listen for the drain
queue.close().then(funciton(){console.log('Queue closed and drained')})
```
## Changelog
### 0.1.0
* Initial release
1 change: 0 additions & 1 deletion helpers/PromiseQ.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var PromiseQueue = function(workers){
* @param {function} next
*/
var jobHandler = function(job,next){
console.log('executing job',job)
//call the function try to get the promise
var rv = job.func()
//make sure we have a promise
Expand Down
29 changes: 0 additions & 29 deletions test.js

This file was deleted.

52 changes: 46 additions & 6 deletions test/PromiseQ.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ var expect = require('chai').expect

var PromiseQ = require('../helpers/PromiseQ')

var job = function(){
return new P(function(resolve){
setTimeout(resolve,10)
})
}


describe('helpers/PromiseQ',function(){
it('should instantiate with worker count',function(){
Expand All @@ -14,15 +20,49 @@ describe('helpers/PromiseQ',function(){
var q = new PromiseQ()
expect(q.workers).to.equal(require('os').cpus().length)
})
it.only('should allow execution of a job',function(done){
it('should allow execution of a job',function(done){
this.timeout(10000)
var q = new PromiseQ()
var job = function(){
q.push(job).then(done).catch(done)
})
it('should close the queue after all jobs finish',function(done){
var q = new PromiseQ()
for(var i = 0; i < 10; i++) q.push(job)
q.close().then(done).catch(done)
})
it('should bubble arguments to the resulting promise',function(done){
var q = new PromiseQ()
q.push(function(){
return new P(function(resolve){

setTimeout(function(){console.log('resolving promise'); resolve()},10)
process.nextTick(function(){
resolve(['foo','bar','baz'])
})
})
})
.then(function(args){
expect(args[0]).to.equal('foo')
expect(args[1]).to.equal('bar')
expect(args[2]).to.equal('baz')
done()
})
.catch(done)
})
it('should bubble errors',function(done){
var q = new PromiseQ()
q.push(function(){
return new P(function(resolve,reject){
process.nextTick(function(){
reject(new Error('foo'))
})
})
})
.then(function(){
done('error didnt bubble')
})
.catch(function(err){
expect(err).to.be.instanceOf(Error)
expect(err.message).to.equal('foo')
done()
})
}
q.push(job).then(done).catch(done)
})
})

0 comments on commit 27917d9

Please sign in to comment.