Permalink
Browse files

ms === 0 for unlimited sessions

  • Loading branch information...
substack committed Jan 2, 2011
1 parent 6e31fd3 commit 5fe61799b550f7a0a398ad2e01a652ef11682aa9
Showing with 30 additions and 5 deletions.
  1. +6 −4 index.js
  2. +1 −1 package.json
  3. +23 −0 test/resources.js
View
@@ -90,10 +90,12 @@ function Resources () {
res.lease.end = res.lease.start + ms;
res.emit = emit;
- setTimeout(function () {
- emit('expire');
- self.release(token);
- }, ms);
+ if (ms > 0) {
+ setTimeout(function () {
+ emit('expire');
+ self.release(token);
+ }, ms);
+ }
emit('available', res.resource, res.key, res.lease);
self.using += 1;
View
@@ -1,6 +1,6 @@
{
"name" : "waitlist",
- "version" : "0.0.3",
+ "version" : "0.0.4",
"description" : "Manage consumers standing in queue for resources.",
"modules" : {
"index" : "./index.js",
View
@@ -151,3 +151,26 @@ exports.release = function (assert) {
assert.deepEqual(resources, [ 1, 0 ]);
}, 100);
};
+
+exports.zero = function (assert) {
+ var ws = new Waitlist;
+ ws.add('zing', {});
+
+ var em = new EventEmitter;
+ var counts = { available : 0, expire : 0 };
+ em.on('available', function (t) {
+ counts.available ++;
+ });
+ em.on('expire', function (t) {
+ counts.expire ++;
+ });
+
+ var t0 = ws.acquire(0, em.emit.bind(em));
+ var t1 = ws.acquire(0, em.emit.bind(em));
+
+ setTimeout(function () {
+ assert.eql(counts.available, 1);
+ assert.eql(counts.expire, 0);
+ ws.remove('zing');
+ }, 100);
+};

0 comments on commit 5fe6179

Please sign in to comment.