-
Notifications
You must be signed in to change notification settings - Fork 0
/
livedatafeed.py
35 lines (25 loc) · 900 Bytes
/
livedatafeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class LiveDataFeed(object):
""" A simple "live data feed" abstraction that allows a reader
to read the most recent data and find out whether it was
updated since the last read.
Interface to data writer:
add_data(data):
Add new data to the feed.
Interface to reader:
read_data():
Returns the most recent data.
has_new_data:
A boolean attribute telling the reader whether the
data was updated since the last read.
"""
def __init__(self):
self.cur_data = None
self.has_new_data = False
def add_data(self, data):
self.cur_data = data
self.has_new_data = True
def read_data(self):
self.has_new_data = False
return self.cur_data
if __name__ == "__main__":
pass