本文整理汇总了Python中rx.observable.Observable.merge方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.merge方法的具体用法?Python Observable.merge怎么用?Python Observable.merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.observable.Observable
的用法示例。
在下文中一共展示了Observable.merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __merge
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import merge [as 别名]
def __merge(self, max_concurrent_or_other):
"""Merges an observable sequence of observable sequences into an
observable sequence, limiting the number of concurrent subscriptions
to inner sequences. Or merges two observable sequences into a single
observable sequence.
1 - merged = sources.merge(1)
2 - merged = source.merge(otherSource)
max_concurrent_or_other [Optional] Maximum number of inner observable
sequences being subscribed to concurrently or the second
observable sequence.
Returns the observable sequence that merges the elements of the inner
sequences.
"""
if isinstance(max_concurrent_or_other, int):
return Observable.merge(max_concurrent_or_other)
sources = self
def subscribe(observer):
active_count = [0]
group = CompositeDisposable()
is_stopped = [False]
q = []
def subscribe(xs):
subscription = SingleAssignmentDisposable()
group.add(subscription)
def on_completed():
group.remove(subscription)
if q.length > 0:
s = q.shift()
subscribe(s)
else:
active_count[0] -= 1
if is_stopped[0] and active_count[0] == 0:
observer.on_completed()
subscription.disposable = xs.subscribe(observer.on_next, observer.on_error, on_completed)
def on_next(inner_source):
if active_count[0] < max_concurrent_or_other:
active_count[0] += 1
subscribe(inner_source)
else:
q.append(inner_source)
def on_completed():
is_stopped[0] = True
if active_count[0] == 0:
observer.on_completed()
group.add(sources.subscribe(on_next, observer.on_error, on_completed))
return group
return AnonymousObservable(subscribe)