Created
April 29, 2015 17:37
-
-
Save i2y/14009b867206ded81c54 to your computer and use it in GitHub Desktop.
RxPY example in Mochi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: mochi -no-mp timer.mochi | |
# original: | |
# https://github.com/ReactiveX/RxPY/blob/master/examples/parallel/timer.py | |
import rx | |
import concurrent.futures | |
import time | |
seconds = [5, 1, 2, 4, 3] | |
def sleep(t): | |
time.sleep(t) | |
return t | |
def output(result): | |
print('%d seconds' % result) | |
with concurrent.futures.ProcessPoolExecutor(5) as executor: | |
rx.Observable.from_(seconds) | |
.flat_map((s) -> executor.submit(sleep, s)) | |
.subscribe(output) | |
# 1 seconds | |
# 2 seconds | |
# 3 seconds | |
# 4 seconds | |
# 5 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment