Skip to content

Instantly share code, notes, and snippets.

@ksc91u
Created November 6, 2016 15:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksc91u/64913e4980c1e09169c06cbba770097d to your computer and use it in GitHub Desktop.
Save ksc91u/64913e4980c1e09169c06cbba770097d to your computer and use it in GitHub Desktop.
RxPy
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