本文整理汇总了Python中rx.observable.Observable.return_value方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.return_value方法的具体用法?Python Observable.return_value怎么用?Python Observable.return_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.observable.Observable
的用法示例。
在下文中一共展示了Observable.return_value方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_select_throws(self):
try:
Observable.return_value(1) \
.select(lambda x, y: x) \
.subscribe(lambda x: _raise("ex"))
except RxException:
pass
try:
Observable.throw_exception('ex') \
.select(lambda x, y: x) \
.subscribe(on_error=lambda ex: _raise(ex))
except RxException:
pass
try:
Observable.empty() \
.select(lambda x, y: x) \
.subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
except RxException:
pass
def subscribe(observer):
_raise('ex')
try:
Observable.create(subscribe) \
.select(lambda x: x) \
.subscribe()
except RxException:
pass
示例2: test_repeat_observable_repeat_count_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_repeat_observable_repeat_count_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).repeat(3)
xs.subscribe(lambda x: _raise('ex'))
with self.assertRaises(RxException):
scheduler1.start()
scheduler2 = TestScheduler()
ys = Observable.throw_exception('ex1', scheduler2).repeat(3)
ys.subscribe(on_error=lambda ex: _raise('ex2'))
with self.assertRaises(RxException):
scheduler2.start()
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).repeat(100)
d = zs.subscribe(on_completed=lambda: _raise('ex3'))
scheduler3.schedule_absolute(10, lambda sc, st: d.dispose())
scheduler3.start()
xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
with self.assertRaises(RxException):
xss.subscribe()
示例3: test_retry_observable_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_retry_observable_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).retry()
xs.subscribe(lambda x: _raise('ex'))
try:
return scheduler1.start()
except RxException:
pass
scheduler2 = TestScheduler()
ys = Observable.throw_exception('ex', scheduler2).retry()
d = ys.subscribe(on_error=lambda ex: _raise('ex'))
scheduler2.schedule_absolute(210, lambda: d.dispose())
scheduler2.start()
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).retry()
zs.subscribe(on_completed=lambda: _raise('ex'))
try:
return scheduler3.start()
except RxException:
pass
xss = Observable.create(lambda o: _raise('ex')).retry()
try:
return xss.subscribe()
except RxException:
pass
示例4: test_repeat_observable_repeat_count_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_repeat_observable_repeat_count_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1).repeat(3)
xs.subscribe(lambda x: _raise('ex'))
try:
return scheduler1.start()
except RxException:
pass
scheduler2 = TestScheduler()
ys = Observable.throwException('ex1', scheduler2).repeat(3)
ys.subscribe(lambda ex: _raise('ex2'))
try:
return scheduler2.start()
except RxException:
pass
scheduler3 = TestScheduler()
zs = Observable.return_value(1, scheduler3).repeat(100)
d = zs.subscribe(on_complete=lambda: _raise('ex3'))
scheduler3.schedule_absolute(10, lambda: d.dispose())
scheduler3.start()
xss = Observable.create(lambda o: _raise('ex4')).repeat(3)
try:
return xss.subscribe()
except RxException:
pass
示例5: test_return_observer_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_return_observer_throws(self):
scheduler1 = TestScheduler()
xs = Observable.return_value(1, scheduler1)
xs.subscribe(lambda x: _raise('ex'))
self.assertRaises(RxException, scheduler1.start)
scheduler2 = TestScheduler()
ys = Observable.return_value(1, scheduler2)
ys.subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
self.assertRaises(RxException, scheduler2.start)
示例6: test_select_with_index_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_select_with_index_throws(self):
try:
return Observable.return_value(1) \
.select(lambda x, index: x) \
.subscribe(lambda x: _raise('ex'))
except RxException:
pass
try:
return Observable.throw_exception('ex') \
.select(lambda x, index: x) \
.subscribe(lambda x: x, lambda ex: _raise(ex))
except RxException:
pass
try:
return Observable.empty() \
.select(lambda x, index: x) \
.subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))
except RxException:
pass
try:
return Observable.create(lambda o: _raise('ex')) \
.select(lambda x, index: x) \
.subscribe()
except RxException:
pass
示例7: repeat
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def repeat(cls, value=None, repeat_count=None, scheduler=None):
"""Generates an observable sequence that repeats the given element the
specified number of times, using the specified scheduler to send out
observer messages.
1 - res = rx.Observable.repeat(42)
2 - res = rx.Observable.repeat(42, 4)
3 - res = rx.Observable.repeat(42, 4, Rx.Scheduler.timeout)
4 - res = rx.Observable.repeat(42, None, Rx.Scheduler.timeout)
Keyword arguments:
value -- Element to repeat.
repeat_count -- [Optional] Number of times to repeat the element. If not
specified, repeats indefinitely.
scheduler -- Scheduler to run the producer loop on. If not specified,
defaults to ImmediateScheduler.
Returns an observable sequence that repeats the given element the
specified number of times."""
scheduler = scheduler or current_thread_scheduler
if repeat_count == -1:
repeat_count = None
xs = Observable.return_value(value, scheduler)
return xs.repeat(repeat_count)
示例8: go
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def go():
source = Observable.return_value(42)
future = source.to_future(asyncio.Future)
def done(future):
try:
value = future.result()
except Exception as ex:
success[1] = False
else:
success[0] = value == 42
future.add_done_callback(done)
示例9: test_select_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_select_throws(self):
with self.assertRaises(RxException):
Observable.return_value(1) \
.map(lambda x, y: x) \
.subscribe(lambda x: _raise("ex"))
with self.assertRaises(RxException):
Observable.throw_exception('ex') \
.map(lambda x, y: x) \
.subscribe(on_error=lambda ex: _raise(ex))
with self.assertRaises(RxException):
Observable.empty() \
.map(lambda x, y: x) \
.subscribe(lambda x: x, lambda ex: ex, lambda: _raise('ex'))
def subscribe(observer):
_raise('ex')
with self.assertRaises(RxException):
Observable.create(subscribe) \
.map(lambda x: x) \
.subscribe()
示例10: test_select_with_index_throws
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_select_with_index_throws(self):
with self.assertRaises(RxException):
return Observable.return_value(1) \
.map(lambda x, index: x) \
.subscribe(lambda x: _raise('ex'))
with self.assertRaises(RxException):
return Observable.throw_exception('ex') \
.map(lambda x, index: x) \
.subscribe(lambda x: x, lambda ex: _raise(ex))
with self.assertRaises(RxException):
return Observable.empty() \
.map(lambda x, index: x) \
.subscribe(lambda x: x, lambda ex: _, lambda : _raise('ex'))
with self.assertRaises(RxException):
return Observable.create(lambda o: _raise('ex')) \
.map(lambda x, index: x) \
.subscribe()
示例11: test_return_disposed_after_next
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def test_return_disposed_after_next(self):
scheduler = TestScheduler()
d = SerialDisposable()
xs = Observable.return_value(42, scheduler)
results = scheduler.create_observer()
def action(scheduler, state):
def on_next(x):
d.dispose()
results.on_next(x)
def on_error(e):
results.on_error(e)
def on_completed():
results.on_completed()
d.disposable = xs.subscribe(on_next, on_error, on_completed)
return d.disposable
scheduler.schedule_absolute(100, action)
scheduler.start()
results.messages.assert_equal(on_next(101, 42))
示例12: factory
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import return_value [as 别名]
def factory():
return Observable.return_value(42, scheduler)