block-sequence
Advanced tools
Comparing version 0.1.2 to 0.1.4
@@ -76,2 +76,3 @@ var EventEmitter = require('events') | ||
queue.push(undefined, cb) | ||
if (queue.paused) self.emit('blocking', sequence || config.sequence) | ||
} | ||
@@ -78,0 +79,0 @@ |
@@ -18,2 +18,4 @@ var debug = require('debug')('block-sequence:blockarray') | ||
self.emit('error', err) | ||
}).on('blocking', function(sequence) { | ||
self.emit('blocking', sequence) | ||
}) | ||
@@ -20,0 +22,0 @@ }) |
{ | ||
"name": "block-sequence", | ||
"version": "0.1.2", | ||
"version": "0.1.4", | ||
"description": "A sequential id generator, which grabs blocks of ids rather than just one at a time", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# block-sequence | ||
A sequential id generator, which grabs blocks of ids rather than just one at a time. | ||
A sequential id generator, which grabs blocks of ids rather than just one at a time. You can configure active/passive blocks and rotate through them, recharging exhausted blocks in the background while assigning ids from the active one. | ||
@@ -56,6 +56,7 @@ ## tl;dr | ||
1. [block-sequence-reference](https://www.npmjs.com/package/block-sequence-reference) (in-memory reference implementation, only useful for testing) | ||
2. [block-sequence-redis](https://www.npmjs.com/package/block-sequence-redis) | ||
3. [block-sequence-mysql](https://www.npmjs.com/package/block-sequence-mysql) | ||
4. [block-sequence-postgres](https://www.npmjs.com/package/block-sequence-postgres) | ||
5. [block-sequence-foxpro](https://www.youtube.com/watch?v=dQw4w9WgXcQ) | ||
2. [block-sequence-mongo](https://www.npmjs.com/package/block-sequence-mongo) | ||
3. [block-sequence-redis](https://www.npmjs.com/package/block-sequence-redis) | ||
4. [block-sequence-mysql](https://www.npmjs.com/package/block-sequence-mysql) | ||
5. [block-sequence-postgres](https://www.npmjs.com/package/block-sequence-postgres) | ||
6. [block-sequence-foxpro](https://www.youtube.com/watch?v=dQw4w9WgXcQ) | ||
@@ -99,6 +100,17 @@ To add another driver please ensure it passes the block-sequence-compliance-tests | ||
## Events | ||
BlockArray emits the following events | ||
### Error | ||
When a block repeatedly fails to recharge and error event is emitted. | ||
### Blocking | ||
The active block always queues id requests, but will usually service them immediately afterwards. When a block is exhausted the next block in the array becomes active and is used to service future id requests, allowing the original block to recharge. During recharge the block's queue is paused. If all other blocks in the array are exhausted before recharge is complete then further id requests will be queued and a 'blocking' event emitted. If you experience this try increasing the block size. | ||
Please note: Since the blocks recharge on startup, but you can start issuing id requests immediately you may receive blocking events while the block array is initialising. | ||
@@ -95,6 +95,29 @@ var bsr = require('block-sequence-reference') | ||
it('should emit a blocking event when queueing', function(done) { | ||
var block = new BlockArray({ | ||
block: { | ||
driver: slowDriver, | ||
size: 1, | ||
sequence: { | ||
name: 'block-tests' | ||
}, | ||
retry: { | ||
limit: 10, | ||
interval: 1 | ||
} | ||
} | ||
}).once('blocking', function(sequence) { | ||
assert.equal(sequence.name, 'block-tests') | ||
done() | ||
}) | ||
async.times(3, function(n, cb) { | ||
block.next(cb) | ||
}) | ||
}) | ||
var badDriver = { | ||
ensure: function(options, cb) { | ||
this.attempts = 0 | ||
cb(null, { name: 'bad-sequence' }) | ||
cb(null, options) | ||
}, | ||
@@ -107,2 +130,15 @@ allocate: function(options, cb) { | ||
var slowDriver = { | ||
ensure: function(options, cb) { | ||
this.attempts = 0 | ||
cb(null, options) | ||
}, | ||
allocate: function(options, cb) { | ||
this.attempts++ | ||
setTimeout(function() { | ||
cb(null, { name: options.name, value: 100 }) | ||
}, 1000) | ||
} | ||
} | ||
}) |
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
18677
373
115