Beispiel #1
0
    def async_get_value(self, key, scheduler=None):
        """Get a value with a specific key.

        :param scheduler: scheduler
        :param key: key

        :return:a future object
        """
        return rx.start(lambda: self.get_value(key), scheduler)
Beispiel #2
0
    def async_set_value(self, key, value, scheduler=None):
        """Set a value with a specific key.

        :param scheduler: scheduler
        :param key: key
        :param value: value

        :return:a future object
        """
        return rx.start(lambda: self.set_value(key, value), scheduler)
Beispiel #3
0
import rx
from rx.scheduler.eventloop import AsyncIOScheduler
import threading
import asyncio


def foo():
    print("foo from {}".format(threading.get_ident()))
    return 2


loop = asyncio.get_event_loop()
done = loop.create_future()
scheduler = AsyncIOScheduler(loop=loop)

number = rx.start(foo, scheduler=scheduler)
print("subscribing...")
number.subscribe(
    lambda i: print("on_next: {} from {}".format(i, threading.get_ident())),
    lambda e: print("on_error: {}".format(e)),
    lambda: done.set_result(0)
)

print("staring mainloop from {}".format(threading.get_ident()))
loop.run_until_complete(done)
loop.close()
Beispiel #4
0
import rx
import threading


def foo():
    print("foo from {}".format(threading.get_ident()))
    return 101


number = rx.start(foo)
print("subscribing...")
number.subscribe(on_next=lambda i: print("on_next: {} from {}".format(
    i, threading.get_ident())),
                 on_error=lambda e: print("error: {}".format(e)),
                 on_completed=lambda: print("completed"))
Beispiel #5
0
        def create():
            def func():
                raise ex

            return rx.start(func, scheduler)
Beispiel #6
0
        def create():
            def func():
                return 1

            return rx.start(func, scheduler)
Beispiel #7
0
        def create():
            def func():
                done[0] = True

            return rx.start(func, scheduler)
# This observable will not output anything and directly emit the complete state.
rx.empty() # 해당 observable 은 아무것도 output 하지 않고 즉시 완료 상태를 발생시킨다.

# This method creates an observable that will never reach the complete state.
rx.never() # 완료 상태에 도달할 수 없는 observable 을 생성한다.


rx.throw()
rx.interval()
rx.from_()
rx.interval()
rx.just()
rx.range()
rx.repeat_value()
rx.start()
rx.timer()

"""Mathematical"""
op.average()
op.concat()
op.count()
op.max()
op.min()
op.reduce()
op.sum()

"""Transformation"""
op.buffer()
op.group_by()
op.map()
Beispiel #9
0
from rx import start
"""
this method takes in a function as an input, and returns an observable 
that will return value from the input function

:parameter
    func: a function that will be called.
    
:return
    it returns an observable that will have a return value from the input function.
"""
lambdas = [lambda: "Hello RxPy", lambda: 5 * 7]

for item in lambdas:
    my_start = start(item)

    my_start.subscribe(lambda x: print("value is {}".format(x)),
                       lambda e: print("error {}".format(e)),
                       lambda: print("Job Done!"))

# result
# value is Hello RxPy
# Job Done!
# value is 35
# Job Done!