new Poller(getRequest, optionsopt)
Poller Class. Inherits from events.EventEmitter. This poller
is designed in that it polls for new items automatically
without having you implement `lastreadId` logic.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getRequest |
itemsGetRequest | request function fired in each poll | ||||||||||||||||
options |
Object |
<optional> |
Properties
|
- 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
pause()
Pause the poller. Note that this does not actually stop the
interval used internally. It basically causes a 'noop' to be
fired instead of an actual network request. This implementation
is simple, and also cheap if you require to pause and resume
multiple times.
- Source:
resume()
Resume the poller, if it was paused.
- Source:
start()
Starts the poller.
- Source:
stop()
Stops the poller.
- Source: