0

I am new to asynchronis programming and think I understand the concept: What is the difference between synchronous and asynchronous programming (in node.js)

I am looking at a project that uses a websockets data feed: http://pastebin.com/dMX7mZE0

var autobahn = require('autobahn');
var wsuri = "wss://api.poloniex.com";
var connection = new autobahn.Connection({
  url: wsuri,
  realm: "realm1"
});

connection.onopen = function (session) {
        function marketEvent (args,kwargs) {
                console.log(args);
        }
        function tickerEvent (args,kwargs) {
                console.log(args);
        }
        function trollboxEvent (args,kwargs) {
                console.log(args);
        }
        session.subscribe('BTC_XMR', marketEvent);
        session.subscribe('ticker', tickerEvent);
        session.subscribe('trollbox', trollboxEvent);
}

connection.onclose = function () {
  console.log("Websocket connection closed");
}

connection.open();

In the example code there are three functions that return data however I am unsure of how to have my code respond to the data returned as these three are continually running simultaneously.

Should I place code to be executed directly within the class methods themselves or would it be better to have the class methods dump their data into a database and then have my code continually reading the database data and acting accordingly?

Thanks and apologies for the noob qn.

Community
  • 1
  • 1
Dercni
  • 1,216
  • 3
  • 18
  • 38
  • What do you mean by `"how to have my code respond"`? – Iceman Jul 16 '16 at 03:38
  • I wish to write a bot that trades in response to the data being returned. – Dercni Jul 16 '16 at 03:44
  • 1
    More of a `socket.io` guy myself but the principle remains same as to have your logic function called thru socket events and return the reponse using the socket. – Iceman Jul 16 '16 at 03:47
  • 1
    Thanks Ice however I don't follow (noob). I'll put an example in the original qn. – Dercni Jul 16 '16 at 03:48
  • Perfect. do that and maybe i can help out more!! – Iceman Jul 16 '16 at 03:49
  • I think I may have confused myself as I having trouble coming up with an example that demonstrates my concerns. Can I ask what you meant by "return the response using the socket" – Dercni Jul 16 '16 at 04:13
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117469/discussion-between-iceman-and-user1567212). – Iceman Jul 16 '16 at 04:14
  • OK, thanks Iceman. – Dercni Jul 16 '16 at 04:32

0 Answers0