Sunday 21 May 2017

I am trying to solve an issue using emit in node

I am querying a webservice. The response comes back with a moreitems available and a version flag.

Is it wrong to call the same invent from inside it like I do in the "if moreitemsavailable=true" statement?

The first run-through works (version 0) - the first "more items available" works as well, and I send through a new request with the updated "xargs".

After this, it seeps to keep looping without updating version or anything else...

any help greatly appreciated... trying to port a solution I have built in Visual Basic to node... (still learning obviously :-( . )

const EventEmitter = require('events');

class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', (a) => {
  console.log('an event occurred!' + a);
});
myEmitter.emit('event', 'ok');


myEmitter.on('act', (session, OwnerId, version) => {
//login=nothing;

  var xargs = {
    "request": {
      "Session": {
        "SessionId": session
      },
      "RequestType": "Owner",
      "version": version,
      "StartTime": "2017-05-16T00:00:00.974+03:00",
      "EndTime": "2017-05-16T23:59:59.974+03:00",
      "Ids": {
        "guid": OwnerId
      }
    }
  };

  console.log(xargs)
  console.log('printer noget')
  soap.createClient(url, function(err, client) {
    console.log(err);

client.GetPeriodActivity(xargs, function(err, login) {
      console.log(err);
      console.log('Get Activity =>')
      console.log(login.GetPeriodActivityResult.StatusMessage);

if (login.GetPeriodActivityResult.Activities != null) {

console.log('the bom length is: ' + login.GetPeriodActivityResult.Activities.VehicleActivity.length);

        if (login.GetPeriodActivityResult.MoreItemsAvailable == true) {
          console.log('der er mere kage');

console.log(login.GetPeriodActivityResult.Version)
          myEmitter.emit('act', session, OwnerId, login.GetPeriodActivityResult.Version)

        }
      };

    });

  })

});


via Morten

No comments:

Post a Comment