本文整理汇总了Python中rx.subjects.Subject.dispose方法的典型用法代码示例。如果您正苦于以下问题:Python Subject.dispose方法的具体用法?Python Subject.dispose怎么用?Python Subject.dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.subjects.Subject
的用法示例。
在下文中一共展示了Subject.dispose方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ControlledSubject
# 需要导入模块: from rx.subjects import Subject [as 别名]
# 或者: from rx.subjects.Subject import dispose [as 别名]
class ControlledSubject(Observable):
def __init__(self, enable_queue=True):
super(ControlledSubject, self).__init__(self._subscribe)
self.subject = Subject()
self.enable_queue = enable_queue
self.queue = [] if enable_queue else None
self.requested_count = 0
self.requested_disposable = Disposable.empty()
self.error = None
self.has_failed = False
self.has_completed = False
self.controlled_disposable = Disposable.empty()
def _subscribe(self, observer):
return self.subject.subscribe(observer)
def on_completed(self):
check_disposed(self)
self.has_completed = True
if not self.enable_queue or not len(self.queue):
self.subject.on_completed()
def on_error(self, error):
check_disposed(self)
self.has_failed = True
self.error = error
if not self.enable_queue or not len(self.queue):
self.subject.on_error(error)
def on_next(self, value):
check_disposed(self)
has_requested = False
if not self.requested_count:
if self.enable_queue:
self.queue.push(value)
else:
if self.requested_count != -1:
requested_count = self.requested_count
self.requested_count -= 1
if requested_count == 0:
self.dispose_current_request()
has_requested = True
if has_requested:
self.subject.on_next(value)
def _process_request(self, number_of_items):
if self.enable_queue:
#console.log('queue length', self.queue.length)
while len(self.queue) >= number_of_items and number_of_items > 0:
# console.log('number of items', number_of_items)
self.subject.on_next(self.queue.shift())
number_of_items -= 1
if len(self.queue):
return { "number_of_items": number_of_items, "return_value": True }
else:
return { "number_of_items": number_of_items, "return_value": False }
if self.has_failed:
self.subject.on_error(self.error)
self.controlled_disposable.dispose()
self.controlled_disposable = Disposable.empty()
elif self.has_completed:
self.subject.on_completed()
self.controlled_disposable.dispose()
self.controlled_disposable = Disposable.empty()
return { "number_of_items": number_of_items, "return_value": False }
def request(self, number):
check_disposed(self)
self.dispose_current_request()
r = self._process_request(number)
number = r["number_of_items"]
if not r["return_value"]:
self.requested_count = number
def action():
self.requested_count = 0
self.requested_disposable = Disposable(action)
return self.requested_disposable
else:
return Disposable.empty()
def dispose_current_request(self):
self.requested_disposable.dispose()
self.requested_disposable = Disposable.empty()
def dispose(self):
self.is_disposed = True # FIXME: something wrong in RxJS?
self.error = None
#.........这里部分代码省略.........