本文整理汇总了Python中rx.core.Observable.never方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.never方法的具体用法?Python Observable.never怎么用?Python Observable.never使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.never方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zip_never_never
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_zip_never_never(self):
scheduler = TestScheduler()
o1 = Observable.never()
o2 = Observable.never()
def create():
return o1.zip(o2, lambda x, y: x + y)
results = scheduler.start(create)
results.messages.assert_equal()
示例2: test_when_never_never
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_when_never_never(self):
scheduler = TestScheduler()
xs = Observable.never()
ys = Observable.never()
def create():
def selector(x, y):
return x + y
return Observable.when(xs.and_(ys).then_do(selector))
results = scheduler.start(create)
results.messages.assert_equal()
示例3: test_zip_non_empty_never
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_zip_non_empty_never(self):
scheduler = TestScheduler()
msgs = [on_next(150, 1), on_next(215, 2), on_completed(220)]
e1 = scheduler.create_hot_observable(msgs)
e2 = Observable.never()
def create():
return e1.zip(e2, lambda x, y: x + y)
results = scheduler.start(create)
results.messages.assert_equal()
示例4: test_replay_time_multiple_connections
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_replay_time_multiple_connections(self):
xs = Observable.never()
ys = xs.replay(None, None, 100)
connection1 = ys.connect()
connection2 = ys.connect()
assert(connection1 == connection2)
connection1.dispose()
connection2.dispose()
connection3 = ys.connect()
assert(connection1 != connection3)
示例5: test_publish_with_initial_value_multiple_connections
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_publish_with_initial_value_multiple_connections(self):
xs = Observable.never()
ys = xs.publish_value(1979)
connection1 = ys.connect()
connection2 = ys.connect()
assert(connection1 == connection2)
connection1.dispose()
connection2.dispose()
connection3 = ys.connect()
assert(connection1 != connection3)
示例6: test_on_error_resume_next_end_with_never
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_on_error_resume_next_end_with_never(self):
scheduler = TestScheduler()
msgs1 = [on_next(150, 1), on_next(210, 2), on_completed(220)]
o1 = scheduler.create_hot_observable(msgs1)
o2 = Observable.never()
def create():
return Observable.on_error_resume_next(o1, o2)
results = scheduler.start(create)
results.messages.assert_equal(on_next(210, 2))
示例7: test_publish_multipleconnections
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_publish_multipleconnections(self):
xs = Observable.never()
ys = xs.publish()
connection1 = ys.connect()
connection2 = ys.connect()
assert(connection1 == connection2)
connection1.dispose()
connection2.dispose()
connection3 = ys.connect()
assert(connection1 != connection3)
connection3.dispose()
示例8: test_zip_never_empty
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_zip_never_empty(self):
scheduler = TestScheduler()
msgs = [on_next(150, 1), on_completed(210)]
o1 = Observable.never()
o2 = scheduler.create_hot_observable(msgs)
def create():
return o1.zip(o2, lambda x, y: x + y)
results = scheduler.start(create)
results.messages.assert_equal()
示例9: test_zip_error_never
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def test_zip_error_never(self):
ex = 'ex'
scheduler = TestScheduler()
msgs2 = [on_next(150, 1), on_error(220, ex)]
e1 = Observable.never()
e2 = scheduler.create_hot_observable(msgs2)
def create():
return e2.zip(e1, lambda x, y: x + y)
results = scheduler.start(create)
results.messages.assert_equal(on_error(220, ex))
示例10: amb
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def amb(cls, *args):
"""Propagates the observable sequence that reacts first.
E.g. winner = rx.Observable.amb(xs, ys, zs)
Returns an observable sequence that surfaces any of the given sequences,
whichever reacted first.
"""
acc = Observable.never()
if isinstance(args[0], list):
items = args[0]
else:
items = list(args)
def func(previous, current):
return previous.amb(current)
for item in items:
acc = func(acc, item)
return acc
示例11: create
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def create():
return Observable.never().scan(lambda acc, x: acc + x)
示例12: create
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def create():
def on_next(x):
i[0] += 1
def on_completed():
completed = True
return Observable.never().do_action(on_next=on_next, on_completed=on_completed)
示例13: create
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def create():
return Observable.never().time_interval(scheduler)
示例14: timeout_with_selector
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def timeout_with_selector(self, first_timeout=None,
timeout_duration_selector=None, other=None):
"""Returns the source observable sequence, switching to the other
observable sequence if a timeout is signaled.
1 - res = source.timeout_with_selector(rx.Observable.timer(500))
2 - res = source.timeout_with_selector(rx.Observable.timer(500),
lambda x: rx.Observable.timer(200))
3 - res = source.timeout_with_selector(rx.Observable.timer(500),
lambda x: rx.Observable.timer(200)),
rx.Observable.return_value(42))
first_timeout -- [Optional] Observable sequence that represents the
timeout for the first element. If not provided, this defaults to
Observable.never().
timeout_Duration_selector -- [Optional] Selector to retrieve an
observable sequence that represents the timeout between the current
element and the next element.
other -- [Optional] Sequence to return in case of a timeout. If not
provided, this is set to Observable.throw_exception().
Returns the source sequence switching to the other sequence in case of
a timeout.
"""
first_timeout = first_timeout or Observable.never()
other = other or Observable.throw_exception(Exception('Timeout'))
source = self
def subscribe(observer):
subscription = SerialDisposable()
timer = SerialDisposable()
original = SingleAssignmentDisposable()
subscription.disposable = original
switched = False
_id = [0]
def set_timer(timeout):
my_id = _id[0]
def timer_wins():
return _id[0] == my_id
d = SingleAssignmentDisposable()
timer.disposable = d
def on_next(x):
if timer_wins():
subscription.disposable = other.subscribe(observer)
d.dispose()
def on_error(e):
if timer_wins():
observer.on_error(e)
def on_completed():
if timer_wins():
subscription.disposable = other.subscribe(observer)
d.disposable = timeout.subscribe(on_next, on_error, on_completed)
set_timer(first_timeout)
def observer_wins():
res = not switched
if res:
_id[0] += 1
return res
def on_next(x):
if observer_wins():
observer.on_next(x)
timeout = None
try:
timeout = timeout_duration_selector(x)
except Exception as e:
observer.on_error(e)
return
set_timer(timeout)
def on_error(e):
if observer_wins():
observer.on_error(e)
def on_completed():
if observer_wins():
observer.on_completed()
original.disposable = source.subscribe(on_next, on_error, on_completed)
return CompositeDisposable(subscription, timer)
return AnonymousObservable(subscribe)
示例15: create
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import never [as 别名]
def create():
return Observable.never().as_observable()