Created
November 6, 2016 15:10
-
-
Save ksc91u/64913e4980c1e09169c06cbba770097d to your computer and use it in GitHub Desktop.
RxPy
This file contains hidden or 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
from __future__ import print_function | |
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( | |
lambda s: executor.submit(sleep, s) | |
).subscribe(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment