示例#1
0
def light_state_equals(light_id: str, light_final_state: str,
                       test_context: Data.TestContext,
                       loop: asyncio.AbstractEventLoop,
                       awaitables: List[RxObservable]):
    assert isinstance(light_id, str)
    assert isinstance(light_final_state, str)

    def take_while_state(payload: Structs.s_lights_state) -> bool:
        return payload.newState != light_final_state

    timeout_sec = 10.0
    lightbulb: Data.Lightbulb = test_context.lightbulbs[light_id]

    observable: RxObservable = lightbulb.light_state.pipe(
        RxOp.timeout(timeout_sec),
        RxOp.observe_on(scheduler=AsyncIOScheduler(loop)),
        RxOp.take_while(take_while_state, inclusive=True),
    )

    observable.subscribe(on_next=lambda i: print(f"on_next: {i}"),
                         on_error=lambda e: print(f"on_error: {e}"),
                         on_completed=lambda: print("on_completed"),
                         scheduler=AsyncIOScheduler(loop))

    awaitables.append(observable)
示例#2
0
def collect(messages: Observable[IbApiMessage]) -> Observable[List[OpenOrder]]:
    # OpenOrders might emit (effective synchronously) something like:
    #  1, (end), 0, 1, (end)
    # Simply ending on the first 'end' would miss order 0, so wait up 1 sec.
    # Note how OPEN_ORDER_END is ignored as a result.
    return messages.pipe(
        _.timeout(0.1), _.on_error_resume_next(empty()),
        _.filter(lambda m: _is_open_order(m)),
        _.reduce(lambda orders, data: _add_data_to_orders(data, orders), {}),
        _.map(lambda orders_map: list(orders_map.values())))
 def _wait_for_order_fill(self,
                          market: Market,
                          client_id: int,
                          max_wait_in_seconds: int = 60):
     self.logger.info(
         f"Waiting up to {max_wait_in_seconds} seconds for {client_id}.")
     return rx.interval(1.0).pipe(
         ops.flat_map(lambda _: market.load_event_queue()),
         ops.skip_while(lambda item: item.client_order_id != client_id),
         ops.skip_while(lambda item: not item.event_flags.fill),
         ops.first(), ops.map(lambda _: True),
         ops.timeout(max_wait_in_seconds, rx.return_value(False))).run()
示例#4
0
 def create():
     return xs.pipe(ops.timeout(100, ys))
示例#5
0
 def create():
     return xs.pipe(ops.timeout(205))
示例#6
0
 def create():
     return xs.pipe(ops.timeout(500, None))
示例#7
0
 def create():
     return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
op.last()
op.skip()
op.skip_last()
op.take()
op.take_last()
# ...

"""Error Handling"""
op.catch()
op.retry()

"""Utility"""
op.delay()
op.materialize()
op.time_interval()
op.timeout()
op.timestamp()

"""Conditional and Boolean"""
op.all()
op.contains()
op.default_if_empty()
op.sequence_equal()
op.skip_until()
op.skip_while()
op.take_until()
op.take_while()

"""Connectable"""
op.publish()
op.ref_count()
 def create():
     return xs.pipe(ops.timeout(100, ys))
 def create():
     return xs.pipe(ops.timeout(205))
 def create():
     return xs.pipe(ops.timeout(500, None))
 def create():
     return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
import rx
import rx.operators as ops
from rx.subject import Subject
import time

numbers = Subject()

numbers.pipe(ops.timeout(0.3)).subscribe(
    on_next=lambda i: print("on_next {}".format(i)),
    on_error=lambda e: print("on_error: {}".format(e)),
    on_completed=lambda: print("on_completed"))

numbers.on_next(1)
numbers.on_next(2)
time.sleep(0.5)
numbers.on_next(3)
numbers.on_next(4)