Class: Poller

poller~Poller

new Poller(getRequest, optionsopt)

Poller Class. Inherits from events.EventEmitter. This poller is designed in that it polls for new updates automatically without having you implement `lastreadId` logic.
Parameters:
Name Type Attributes Description
getRequest itemsGetRequest
options Object <optional>
Properties
Name Type Attributes Default Description
params Object | function <optional>
parameters passed to get request. If `options.params` is a function, it is called and it return value is assumed an object as the request params. If `options.params` requires to do an asynchronous action, it is passed a `done` function as its only argument to call with the value when done.
interval Integer <optional>
5000 configures the poller's timer
Source:
Example
// create a new poller that keeps retrieiving traffic updates
var poller = new sdk.Poller(sdk.trafficUpdates.get, {
  interval: 5000, // 5 seconds
});

// listen for new updates
poller.on("message", function(updates, meta, responseObject) {
  console.log("received these updates: %j", updates);
});

// listen for errors e.g. network failures etc.
// if an error occurs an you not listening on the "error"
// event, the error will bubble up to the domain/process.
poller.on("error", function(err) {
  console.log("error: %s", err);
});

// you have to explicitly start it
poller.start();

// lets say we close it after a minute or so
setTimeout(function() {
  poller.stop();
}, 1000 * 60);

Methods

start()

Starts the poller
Source:

stop()

Stops the poller
Source: