本文整理汇总了Python中rx.core.Observable.create_with_disposable方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.create_with_disposable方法的具体用法?Python Observable.create_with_disposable怎么用?Python Observable.create_with_disposable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.create_with_disposable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create_with_disposable [as 别名]
def create():
def subscribe(o):
d = BooleanDisposable()
o.on_next(1)
o.on_next(2)
def action1(scheduler, state):
if not d.is_disposed:
o.on_next(3)
scheduler.schedule_relative(600, action1)
def action2(scheduler, state):
if not d.is_disposed:
o.on_next(4)
scheduler.schedule_relative(700, action2)
def action3(scheduler, state):
if not d.is_disposed:
o.on_next(5)
scheduler.schedule_relative(900, action3)
def action4(scheduler, state):
if not d.is_disposed:
o.on_next(6)
scheduler.schedule_relative(1100, action4)
return d
return Observable.create_with_disposable(subscribe)
示例2: test_create_with_disposable_observer_throws
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create_with_disposable [as 别名]
def test_create_with_disposable_observer_throws(self):
def subscribe1(o):
o.on_next(1)
return Disposable.empty()
def on_next(x):
_raise("ex")
with self.assertRaises(RxException):
Observable.create_with_disposable(subscribe1).subscribe(on_next)
def subscribe2(o):
o.on_error("exception")
return Disposable.empty()
with self.assertRaises(RxException):
Observable.create_with_disposable(subscribe2).subscribe(on_error=lambda ex: _raise("ex"))
def subscribe3(o):
o.on_completed()
return Disposable.empty()
with self.assertRaises(RxException):
Observable.create_with_disposable(subscribe3).subscribe(on_completed=_raise("ex"))
示例3: test_create_with_disposable_exception
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import create_with_disposable [as 别名]
def test_create_with_disposable_exception(self):
with self.assertRaises(RxException):
Observable.create_with_disposable(lambda: o, _raise("ex")).subscribe()