Permalink
Browse files

Added emit callback's and bug fixes

v0.2.2
* Completed code to allow for callbacks and partial callbacks to be
issued back to emit statements
* Complteed refactoring of code to properly seperate functionality into
objects
  • Loading branch information...
jdarling committed Jul 31, 2012
1 parent 5669f5e commit 2e5b7eb914292fb00f2d536a1703b984464363ba
Showing with 801 additions and 518 deletions.
  1. +12 −0 .project
  2. +1 −1 bin/MongoMQ.js
  3. +55 −4 bin/test.js
  4. +233 −62 lib/MongoConnection.js
  5. +313 −262 lib/MongoMQ.js
  6. +0 −181 lib/MongoMQ_bu.js
  7. +175 −0 lib/QueueListener.js
  8. +3 −2 package.json
  9. +9 −6 readme.md
View
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MongoMQ</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.aptana.projects.webnature</nature>
+ </natures>
+</projectDescription>
View
@@ -41,7 +41,7 @@ for(funcName in queue){
r.context.logAny = function(){
queue.onAny(function(err, data, next){
- console.log(data);
+ console.log(err, data);
next();
});
};
View
@@ -18,13 +18,25 @@ r.context.send = function(){
msgidx++;
};
+r.context.send2 = function(){
+ queue.emit('test2', msgidx);
+ msgidx++;
+};
+
r.context.load = function(){
for(var i = 0; i<100; i++){
queue.emit('test', msgidx);
msgidx++;
}
};
+r.context.load2 = function(){
+ for(var i = 0; i<100; i++){
+ queue.emit('test2', msgidx);
+ msgidx++;
+ }
+};
+
var logMsg = function(err, data, next){
console.log('LOG: ', data);
next();
@@ -33,6 +45,10 @@ var eatTest = function(err, data, next){
console.log('eat: ', data);
next();
};
+var eatTest2 = function(err, data, next){
+ console.log('eat2: ', data);
+ next();
+ };
r.context.logAny = function(){
queue.onAny(logMsg);
@@ -42,6 +58,10 @@ r.context.eatTest = function(){
queue.on('test', eatTest);
};
+r.context.eatTest2 = function(){
+ queue.on('test2', eatTest2);
+};
+
r.context.start = function(cb){
queue.start(cb);
};
@@ -50,6 +70,27 @@ r.context.stop = function(){
queue.stop();
};
+r.context.testOnce = function(){
+ var handlers = queue.once('once', function(err, data, next){
+ console.log('testOnce: ', data);
+ next();
+ });
+ queue.emit('once', {foo: 'bar3'});
+};
+
+r.context.testAll = function(){
+ r.context.logAny();
+ r.context.eatTest();
+ r.context.eatTest2();
+ r.context.testOnce();
+ r.context.send();
+ r.context.send2();
+ r.context.load();
+ r.context.load2();
+ r.context.testOnce();
+ r.context.testOnce();
+};
+
r.context.help = function(){
console.log('Built in test methods:\r\n'+
' help() - shows this message\r\n'+
@@ -65,12 +106,22 @@ r.context.help = function(){
return '';
};
-/*
+r.context.tmp = function(){
+ queue.on('foo', function(err, data, next){
+ console.log('foo got: ', err||data);
+ next({some: 'data', bar: data.bar});
+ next({more: 'data', bar: data.bar});
+ next({done: 'data', bar: data.bar}, true);
+ });
+ queue.emit('foo', {bar: 'none'}, function(err, data, next){console.log('test: ', data); next();});
+ queue.emit('foo', {bar: 'some'}, function(err, data, next){console.log('partial: ', data); next();}, function(err, data, next){console.log('complete: ', data); next();});
+};
+
+//*
queue.start(function(){
- r.context.eatTest();
});
-*/
+//*/
r.context.queue = queue;
-
+//process.stdout.write('\u001B[2J\u001B[0;0f');
r.context.help();
Oops, something went wrong.

0 comments on commit 2e5b7eb

Please sign in to comment.