Skip to content

Commit

Permalink
Make Event Polling a little bit more customizable.
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Aug 28, 2014
1 parent f0e5972 commit 71d1683
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions lib/src/common/events.dart
Expand Up @@ -12,15 +12,13 @@ class EventPoller {

EventPoller(this.github, this.path);

Stream<Event> start() {
Stream<Event> start({bool onlyNew: false, int interval}) {
if (_timer != null) {
throw new Exception("Polling already started.");
}

_controller = new StreamController();

int interval;

void handleEvent(http.Response response) {
if (interval == null) {
interval = int.parse(response.headers['x-poll-interval']);
Expand All @@ -32,16 +30,18 @@ class EventPoller {

var json = JSON.decode(response.body);

for (var item in json) {
var event = Event.fromJSON(github, item);

if (handledEvents.contains(event.id)) {
continue;
if (!(onlyNew && _timer == null)) {
for (var item in json) {
var event = Event.fromJSON(github, item);

if (handledEvents.contains(event.id)) {
continue;
}

handledEvents.add(event.id);

_controller.add(event);
}

handledEvents.add(event.id);

_controller.add(event);
}

if (_timer == null) {
Expand Down
2 changes: 1 addition & 1 deletion test/polling.dart
Expand Up @@ -5,7 +5,7 @@ void main() {

var github = new GitHub(auth: new Authentication.withToken("5fdec2b77527eae85f188b7b2bfeeda170f26883"));

var poller = github.pollPublicEvents();
EventPoller poller = github.pollPublicEvents();

poller.start().listen((event) {
print("New Event:");
Expand Down

0 comments on commit 71d1683

Please sign in to comment.