Skip to content

Commit 71d1683

Browse files
committed
Make Event Polling a little bit more customizable.
1 parent f0e5972 commit 71d1683

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

lib/src/common/events.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ class EventPoller {
1212

1313
EventPoller(this.github, this.path);
1414

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

2020
_controller = new StreamController();
2121

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

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

35-
for (var item in json) {
36-
var event = Event.fromJSON(github, item);
37-
38-
if (handledEvents.contains(event.id)) {
39-
continue;
33+
if (!(onlyNew && _timer == null)) {
34+
for (var item in json) {
35+
var event = Event.fromJSON(github, item);
36+
37+
if (handledEvents.contains(event.id)) {
38+
continue;
39+
}
40+
41+
handledEvents.add(event.id);
42+
43+
_controller.add(event);
4044
}
41-
42-
handledEvents.add(event.id);
43-
44-
_controller.add(event);
4545
}
4646

4747
if (_timer == null) {

test/polling.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void main() {
55

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

8-
var poller = github.pollPublicEvents();
8+
EventPoller poller = github.pollPublicEvents();
99

1010
poller.start().listen((event) {
1111
print("New Event:");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy