Leah
Leah

Reputation: 29

How to combine 2 observables into one and leave only the changed values using rxpy

I'm new with reactiveX concept and I need to use rxpy v4.
My code has 2 infinite loops and for each one of them I need to create observable BUT I need to combine them into one, and filter the values so the combined observable will contain the only last values that were changes.

so my questions are:

  1. what is best approach to create observable?

  2. how can combine/merge the 2 of them?

My code looks like:

async def task1(ob1):
    while True:
        # insert random value to ob1

async def task2(ob2):
    while True:
        # insert random value to ob2

async def main():
    ob1 = # todo - create observable
    ob2 = # todo - create observable
    # todo- combine/merge ob1 and ob2, leave only latest changes
    await asyncio.gather(task1(ob1), task2(ob2))


if __name__ == "__main__":
    asyncio.run(main())

Upvotes: 0

Views: 35

Answers (0)

Related Questions