Skip to content

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

@cheind

Description

@cheind

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions