Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxPY/ example / timer.py broken: Future is not iterable #709

Open
cheind opened this issue Nov 23, 2023 · 0 comments
Open

RxPY/ example / timer.py broken: Future is not iterable #709

cheind opened this issue Nov 23, 2023 · 0 comments

Comments

@cheind
Copy link

cheind commented Nov 23, 2023

Describe the bug

Maybe I'm not seeing something, but I believe the example

https://github.com/ReactiveX/RxPY/blob/master/examples/parallel/timer.py

is broken for RxPY 4.0.4. Instead of printing the output it prints nothing, which is due to the on_error handler being called. Once hooked it states that Future is not iterable.

To Reproduce

python timer.py

Expected behavior

See output

1 seconds
2 seconds
3 seconds
4 seconds
5 seconds 

Fix

I believe the correct code should read

   with concurrent.futures.ProcessPoolExecutor(5) as executor:
        reactivex.from_(seconds).pipe(
            ops.flat_map(lambda s: reactivex.from_future(executor.submit(sleep, s)))
        ).subscribe(output)

Additional context

  • Linux
  • RxPY 4.0.4
  • Python 3.11

Question
Why is flat_map used in this context. Does it enable parallel features in some way compared to map?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant