本文整理汇总了Python中rx.disposables.SingleAssignmentDisposable类的典型用法代码示例。如果您正苦于以下问题:Python SingleAssignmentDisposable类的具体用法?Python SingleAssignmentDisposable怎么用?Python SingleAssignmentDisposable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SingleAssignmentDisposable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_next_right
def on_next_right(value):
duration = None
current_id = right_id[0]
right_id[0] += 1
md = SingleAssignmentDisposable()
right_map[current_id] = value
group.add(md)
def expire():
if current_id in right_map:
del right_map[current_id]
if not len(right_map) and right_done[0]:
observer.on_completed()
return group.remove(md)
try:
duration = right_duration_selector(value)
except Exception as exception:
log.error("*** Exception: %s" % exception)
observer.on_error(exception)
return
md.disposable = duration.take(1).subscribe(noop, observer.on_error, lambda: expire())
for val in left_map.values():
try:
result = result_selector(val, value)
except Exception as exception:
log.error("*** Exception: %s" % exception)
observer.on_error(exception)
return
observer.on_next(result)
示例2: action
def action(action1, state=None):
current = None
def on_error(exn):
nonlocal last_exception
last_exception = exn
action1()
if is_disposed:
return
try:
current = next(e)
except StopIteration:
if last_exception:
observer.on_error(last_exception)
else:
observer.on_completed()
except Exception as ex:
observer.on_error(ex)
else:
d = SingleAssignmentDisposable()
subscription.disposable = d
d.disposable = current.subscribe(
observer.on_next,
on_error,
observer.on_completed
)
示例3: subscribe
def subscribe(observer):
m = SingleAssignmentDisposable()
group = CompositeDisposable()
is_stopped = False
group.add(m)
def on_next(inner_source):
inner_subscription = SingleAssignmentDisposable()
group.add(inner_subscription)
def on_complete():
nonlocal group
group.remove(inner_subscription)
if is_stopped and group.length == 1:
observer.on_completed()
disposable = inner_source.subscribe(
observer.on_next,
observer.on_error,
on_complete)
inner_subscription.disposable = disposable
def on_complete():
nonlocal is_stopped
is_stopped = True
if group.length == 1:
observer.on_completed()
m.disposable = sources.subscribe(on_next, observer.on_error, on_complete)
return group
示例4: on_next
def on_next(x):
nonlocal value, has_value, _id
throttle = None
try:
throttle = throttle_duration_selector(x)
except Exception as e:
observer.on_error(e)
return
has_value = True
value = x
_id += 1
current_id = _id
d = SingleAssignmentDisposable()
cancelable.disposable = d
def on_next(x):
nonlocal has_value
if has_value and _id == current_id:
observer.on_next(value)
has_value = False
d.dispose()
def on_completed():
nonlocal has_value
if has_value and _id == current_id:
observer.on_next(value)
has_value = False
d.dispose()
d.disposable = throttle.subscribe(on_next, observer.on_error, on_completed)
示例5: on_next_right
def on_next_right(value):
_id = right_id[0]
right_id[0] += 1
right_map[_id] = value
md = SingleAssignmentDisposable()
group.add(md)
def expire():
del right_map[_id]
group.remove(md)
try:
duration = right_duration_selector(value)
except Exception as e:
for left_value in left_map.values():
left_value.on_error(e)
observer.on_error(e)
return
def on_error(e):
for left_value in left_map.values():
left_value.on_error(e)
observer.on_error(e)
md.disposable = duration.take(1).subscribe(
nothing,
on_error,
expire)
for left_value in left_map.values():
left_value.on_next(value)
示例6: on_next
def on_next(notification):
log.debug("observable_delay_timespan:subscribe:on_next()")
should_run = False
with self.lock:
if notification.value.kind == 'E':
del queue[:]
queue.append(notification)
exception[0] = notification.value.exception
should_run = not running[0]
else:
queue.append(Timestamp(value=notification.value, timestamp=notification.timestamp + duetime))
should_run = not active[0]
active[0] = True
if should_run:
if exception[0]:
log.error("*** Exception: %s", exception[0])
observer.on_error(exception[0])
else:
d = SingleAssignmentDisposable()
cancelable.disposable = d
def action(this):
if exception[0]:
log.error("observable_delay_timespan:subscribe:on_next:action(), exception: %s", exception[0])
return
with self.lock:
running[0] = True
while True:
result = None
if len(queue) and queue[0].timestamp <= scheduler.now():
result = queue.pop(0).value
if result:
result.accept(observer)
if not result:
break
should_recurse = False
recurse_duetime = 0
if len(queue) :
should_recurse = True
diff = queue[0].timestamp - scheduler.now()
zero = timedelta(0) if isinstance(diff, timedelta) else 0
recurse_duetime = max(zero, diff)
else:
active[0] = False
ex = exception[0]
running[0] = False
if ex:
observer.on_error(ex)
elif should_recurse:
this(recurse_duetime)
d.disposable = scheduler.schedule_recursive_with_relative(duetime, action)
示例7: ScheduledItem
class ScheduledItem(object):
def __init__(self, scheduler, state, action, duetime, comparer=None):
self.scheduler = scheduler
self.state = state
self.action = action
self.duetime = duetime
self.comparer = comparer or default_sub_comparer
self.disposable = SingleAssignmentDisposable()
def invoke(self):
self.disposable.disposable = self.invoke_core()
def compare_to(self, other):
return self.comparer(self.duetime, other.duetime)
def cancel(self):
"""Cancels the work item by disposing the resource returned by
invoke_core as soon as possible."""
self.disposable.dispose()
def is_cancelled(self):
return self.disposable.is_disposed
def invoke_core(self):
return self.action(self.scheduler, self.state)
def __lt__(self, other):
return self.compare_to(other) < 0
def __gt__(self, other):
return self.compare_to(other) > 0
def __eq__(self, other):
return self.compare_to(other) == 0
示例8: AutoDetachObserver
class AutoDetachObserver(AbstractObserver):
def __init__(self, observer):
super(AutoDetachObserver, self).__init__(self._next, self._error, self._completed)
self.observer = observer
self.m = SingleAssignmentDisposable()
def _next(self, value):
try:
self.observer.on_next(value)
except Exception:
self.dispose()
raise
def _error(self, exn):
try:
self.observer.on_error(exn)
finally:
self.dispose()
def _completed(self):
try:
self.observer.on_completed()
finally:
self.dispose()
def set_disposable(self, value):
self.m.disposable = value
disposable = property(fset=set_disposable)
def dispose(self):
super(AutoDetachObserver, self).dispose()
self.m.dispose()
示例9: on_next
def on_next(inner_source):
nonlocal latest, has_latest
d = SingleAssignmentDisposable()
latest += 1
_id = latest
has_latest = True
inner_subscription.disposable = d
def on_next(x):
if latest == _id:
observer.on_next(x)
def on_error(e):
if latest == _id:
observer.on_error(e)
def on_completed():
nonlocal has_latest
if latest == _id:
has_latest = False
if is_stopped:
observer.on_completed()
d.disposable = inner_source.subscribe(on_next, on_error, on_completed)
示例10: action
def action(this, state):
if len(q) > 0:
work = q.pop(0)
else:
is_acquired[0] = False
return
m1 = SingleAssignmentDisposable()
d.add(m1)
def on_next(x):
observer.on_next(x)
result = None
try:
result = selector(x)
except Exception as ex:
observer.on_error(ex)
q.append(result)
active_count[0] += 1
ensure_active()
def on_complete():
d.remove(m1)
active_count[0] -= 1
if active_count[0] == 0:
observer.on_completed()
m1.disposable = work.subscribe(on_next, observer.on_error, on_complete)
this()
示例11: AutoDetachObserver
class AutoDetachObserver(AbstractObserver):
def __init__(self, observer):
super(AutoDetachObserver, self).__init__()
self.observer = observer
self.m = SingleAssignmentDisposable()
def next(self, value):
try:
self.observer.on_next(value)
except Exception as ex:
traceback.print_exc(file=sys.stdout)
self.dispose()
def error(self, exn):
try:
self.observer.on_error(exn)
finally:
self.dispose()
def completed(self):
try:
self.observer.on_completed()
finally:
self.dispose()
def set_disposable(self, value):
self.m.disposable = value
disposable = property(fset=set_disposable)
def dispose(self):
super(AutoDetachObserver, self).dispose()
self.m.dispose()
示例12: on_next
def on_next(inner_source):
d = SingleAssignmentDisposable()
with self.lock:
latest[0] += 1
_id = latest[0]
has_latest[0] = True
inner_subscription.disposable = d
# Check if Future or Observable
inner_source = Observable.from_future(inner_source)
def on_next(x):
if latest[0] == _id:
observer.on_next(x)
def on_error(e):
if latest[0] == _id:
observer.on_error(e)
def on_completed():
if latest[0] == _id:
has_latest[0] = False
if is_stopped[0]:
observer.on_completed()
d.disposable = inner_source.subscribe(on_next, on_error, on_completed)
示例13: on_next
def on_next(x):
throttle = None
try:
throttle = throttle_duration_selector(x)
except Exception as e:
observer.on_error(e)
return
has_value[0] = True
value[0] = x
_id[0] += 1
current_id = _id[0]
d = SingleAssignmentDisposable()
cancelable.disposable = d
def on_next(x):
if has_value[0] and _id[0] == current_id:
observer.on_next(value[0])
has_value[0] = False
d.dispose()
def on_completed():
if has_value[0] and _id[0] == current_id:
observer.on_next(value[0])
has_value[0] = False
d.dispose()
d.disposable = throttle.subscribe(on_next, observer.on_error,
on_completed)
示例14: subscribe_all
def subscribe_all(parent, *children):
values = [NO_VALUE for _ in children]
def subscribe_child(i, child):
subscription = SingleAssignmentDisposable()
def on_next(value):
with parent.lock:
values[i] = value
subscription.disposable = child.subscribe(
on_next, observer.on_error)
return subscription
parent_subscription = SingleAssignmentDisposable()
def on_next(value):
with parent.lock:
if NO_VALUE not in values:
try:
result = result_selector(value, *values)
except Exception as error:
observer.on_error(error)
else:
observer.on_next(result)
parent_subscription.disposable = parent.subscribe(
on_next, observer.on_error, observer.on_completed)
return listify_args(
parent_subscription,
*(subscribe_child(*a) for a in enumerate(children))
)
示例15: subscribe
def subscribe(observer):
m = SingleAssignmentDisposable()
group = CompositeDisposable()
is_stopped = [False]
group.add(m)
def on_next(inner_source):
inner_subscription = SingleAssignmentDisposable()
group.add(inner_subscription)
inner_source = Observable.from_future(inner_source)
def on_complete():
group.remove(inner_subscription)
if is_stopped[0] and group.length == 1:
observer.on_completed()
disposable = inner_source.subscribe(
observer.on_next,
observer.on_error,
on_complete)
inner_subscription.disposable = disposable
def on_complete():
is_stopped[0] = True
if group.length == 1:
observer.on_completed()
m.disposable = sources.subscribe(on_next, observer.on_error, on_complete)
return group