Skip to content

Commit 5ad905e

Browse files
committed
Use Stream.connect to loop the fib examples
1 parent 2eba95a commit 5ad905e

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

examples/fib_asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
s = source.sliding_window(2).map(sum)
77
L = s.sink_to_list() # store result in a list
88

9-
s.rate_limit('500ms').sink(source.emit) # pipe output back to input
109
s.rate_limit('1s').sink(lambda x: print(L)) # print state of L every second
10+
s.rate_limit('500ms').connect(source) # pipe output back to input
1111

12-
source.emit(1) # seed with initial values, does not block thread due to Future return
12+
source.emit(1) # seed with initial value, does not block thread due to Future return
1313

1414
try:
1515
asyncio.get_event_loop().run_forever()

examples/fib_thread.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
s = source.sliding_window(2).map(sum)
55
L = s.sink_to_list() # store result in a list
66

7-
s.rate_limit('500ms').sink(source.emit) # pipe output back to input
87
s.rate_limit('1s').sink(lambda x: print(L)) # print state of L every second
8+
s.rate_limit('500ms').connect(source) # pipe output back to input
99

1010
try:
11-
source.emit(1) # seed with initial values, blocks thread due to cycle in stream
11+
source.emit(1) # seed with initial value, blocks thread due to cycle in stream
1212
except KeyboardInterrupt:
1313
pass

examples/fib_tornado.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
s = source.sliding_window(2).map(sum)
77
L = s.sink_to_list() # store result in a list
88

9-
s.rate_limit('500ms').sink(source.emit) # pipe output back to input
109
s.rate_limit('1s').sink(lambda x: print(L)) # print state of L every second
10+
s.rate_limit('500ms').connect(source) # pipe output back to input
1111

12-
source.emit(1) # seed with initial values, does not block thread due to Future return
12+
source.emit(1) # seed with initial value, does not block thread due to Future return
1313

1414
try:
1515
IOLoop.current().start()

0 commit comments

Comments
 (0)