Skip to content

Commit

Permalink
Added emit callback's and bug fixes
Browse files Browse the repository at this point in the history
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 2e5b7eb
Show file tree
Hide file tree
Showing 9 changed files with 801 additions and 518 deletions.
12 changes: 12 additions & 0 deletions .project
@@ -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>
2 changes: 1 addition & 1 deletion bin/MongoMQ.js
Expand Up @@ -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();
});
};
Expand Down
59 changes: 55 additions & 4 deletions bin/test.js
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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);
};
Expand All @@ -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'+
Expand All @@ -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();

0 comments on commit 2e5b7eb

Please sign in to comment.