0

I m using following code to execute my functions in a serial order. ie executing first function and then the second function.but what this code does is,it starts with the first function and immediately it skips to second function.It is not completely executing the first function.

var Step = require('step'); 
Step(
  function first()
  {
    console.log(" [x] Sent %s");
    var amqp = require('amqplib/callback_api');
    amqp.connect('amqp://localhost', function(err, conn) 
                 {
      conn.createChannel(function(err, ch) 
                         {
        var q = 'hello';
        var msg='hello world';
        ch.assertQueue(q, {durable: false});
        // Note: on Node 6 Buffer.from(msg) should be used
        ch.sendToQueue(q, new Buffer(msg));
        console.log(" [x] Sent %s", msg);
      });
    });
    this() //Calling second function
  },
  function second()
  {
    console.log('second');
  }
)
Kukic Vladimir
  • 1,010
  • 4
  • 15
  • 22
Developer
  • 61
  • 10
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Brahma Dev Sep 25 '17 at 10:26
  • Why are you making call to `this()` the function second will automatically be invoke after the first function is done its execution. – Shubham Jain Sep 25 '17 at 13:28

0 Answers0