0

I have this simple code:

  server.getConnections(function(err, count) {
    console.log(count)
    this.connections = count;
    return connections
  });
    console.log(connections);

I get connection is undefined but count has value of 1 actually.

What am I doing wrong?

Villemh
  • 197
  • 2
  • 14
  • Because you're assigning to `this.connections`? – Amit Mar 05 '16 at 15:23
  • 1
    This seems like a mixture of programming basics and http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – baao Mar 05 '16 at 15:24
  • thank you the comment with the link to async function return was helpful. – Villemh Mar 05 '16 at 15:27
  • Lye Fish what do you mean im not calling the function? Im calling server.getConnection() and this is the callback function form which I want to return the count? – Villemh Mar 05 '16 at 15:29
  • You miss a few semicolons .. and shouldn't it be `return this.connections;` ? – Asons Mar 05 '16 at 15:43

0 Answers0