"use strict";

//node
var EventEmitter = require('events').EventEmitter;
var util = require('util');

var Queue = require('./queue');

//Empty AMQP Mock Object
function AMQP() {
  // Call the super EventEmitter constructor.
  EventEmitter.call(this);
  // Mock Connection Object
  this.connection = {};
}

//Inherit EventEmitter Prototype Methods
AMQP.prototype = Object.create( EventEmitter.prototype );

AMQP.prototype.publish = function(routingKey, message, options, callback) {
  callback(false);
};

AMQP.prototype.queue = function(name, options, callback) {
  return new Queue(this, null, name, options, callback);
};

//Most Connection Creation Call
AMQP.prototype.createConnection = function () {

  this.connection = {
    publish : function(routingKey, message, options, callback) {
      if (typeof callback === 'function') callback()
    }
  };

  setTimeout(function() {
    this.emit("ready");
  }.bind(this));

  return this;
};


AMQP.prototype.exchange = function(name, options, callback) {
  callback({
    name : name,
    connection : this.connection
  });

  setTimeout(function() {
    this.emit("exchangeBound");
  }.bind(this));

  return this;
};


module.exports = AMQP;

@@ -1,8 +1,29 @@
+/*global process */%0A%0A
 %22use str
@@ -718,16 +718,35 @@
 ion () %7B
+%0A  var self = this;
 %0A%0A  this
@@ -889,34 +889,40 @@
   %7D%0A  %7D;%0A%0A  
-setTimeout
+process.nextTick
 (function() 
@@ -910,32 +910,33 @@
 extTick(function
+ 
 () %7B%0A    this.em
@@ -924,28 +924,28 @@
 on () %7B%0A    
-this
+self
 .emit(%22ready
@@ -947,35 +947,24 @@
 ready%22);%0A  %7D
-.bind(this)
 );%0A%0A  return
@@ -1029,32 +1029,52 @@
 ns, callback) %7B%0A
+  var self = this;%0A%0A
   callback(%7B%0A   
@@ -1133,18 +1133,24 @@
 %0A%0A  
-setTimeout
+process.nextTick
 (fun
@@ -1154,16 +1154,17 @@
 function
+ 
 () %7B%0A   
@@ -1164,20 +1164,20 @@
 ) %7B%0A    
-this
+self
 .emit(%22e
@@ -1199,19 +1199,8 @@
 %0A  %7D
-.bind(this)
 );%0A%0A

update mocks to use process.nextTick