本文整理汇总了Python中rx.observable.Observable.from_future方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.from_future方法的具体用法?Python Observable.from_future怎么用?Python Observable.from_future使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.observable.Observable
的用法示例。
在下文中一共展示了Observable.from_future方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: take_until
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def take_until(self, other):
"""Returns the values from the source observable sequence until the
other observable sequence produces a value.
Keyword arguments:
other -- Observable sequence that terminates propagation of elements of
the source sequence.
Returns an observable sequence containing the elements of the source
sequence up to the point the other sequence interrupted further
propagation.
"""
source = self
other = Observable.from_future(other)
def subscribe(observer):
def on_completed(x):
observer.on_completed()
return CompositeDisposable(
source.subscribe(observer),
other.subscribe(on_completed, observer.on_error, noop)
)
return AnonymousObservable(subscribe)
示例2: on_next
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
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)
示例3: subscribe
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def subscribe(observer):
try:
result = observable_factory()
except Exception as ex:
return Observable.throw_exception(ex).subscribe(observer)
result = Observable.from_future(result)
return result.subscribe(observer)
示例4: action
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def action(this, state=None):
if pos[0] < len(sources):
current = Observable.from_future(sources[pos[0]])
pos[0] += 1
d = SingleAssignmentDisposable()
subscription.disposable = d
d.disposable = current.subscribe(observer.on_next, lambda ex: this(), lambda: this())
else:
observer.on_completed()
示例5: on_error
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def on_error(exception):
try:
result = handler(exception)
except Exception as ex:
observer.on_error(ex)
return
result = Observable.from_future(result)
d = SingleAssignmentDisposable()
subscription.disposable = d
d.disposable = result.subscribe(observer)
示例6: func
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def func(i):
source = sources[i]
sad = SingleAssignmentDisposable()
source = Observable.from_future(source)
def on_next(x):
queues[i].append(x)
next(i)
sad.disposable = source.subscribe(on_next, observer.on_error, lambda: done(i))
subscriptions[i] = sad
示例7: while_do
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def while_do(cls, condition, source):
"""Repeats source as long as condition holds emulating a while loop.
Keyword arguments:
condition -- {Function} The condition which determines if the source
will be repeated.
source -- {Observable} The observable sequence that will be run if the
condition function returns true.
Returns an observable {Observable} sequence which is repeated as long
as the condition holds."""
source = Observable.from_future(source)
return Observable.concat(Enumerable.while_do(condition, source))
示例8: action
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def action(this, state=None):
try:
source = next(sources)
except StopIteration:
observer.on_completed()
return
# Allow source to be a factory method taking an error
source = source(state) if callable(source) else source
current = Observable.from_future(source)
d = SingleAssignmentDisposable()
subscription.disposable = d
d.disposable = current.subscribe(observer.on_next, lambda ex: this(ex), this)
示例9: on_next
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def on_next(inner_source):
inner_subscription = SingleAssignmentDisposable()
group.add(inner_subscription)
inner_source = Observable.from_future(inner_source)
def on_next(x):
observer.on_next(x)
def on_completed():
group.remove(inner_subscription)
if is_stopped and group.length == 1:
observer.on_completed()
inner_subscription.disposable = inner_source.subscribe(on_next, observer.on_error, on_completed)
示例10: while_do
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def while_do(cls, condition, source):
"""Repeats source as long as condition holds emulating a while loop.
Keyword arguments:
:param types.FunctionType condition: The condition which determines if the
source will be repeated.
:param Observable source: The observable sequence that will be run if the
condition function returns true.
:returns: An observable sequence which is repeated as long as the condition
holds.
:rtype: Observable
"""
source = Observable.from_future(source)
return Observable.concat(Enumerable.while_do(condition, source))
示例11: start_async
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def start_async(cls, function_async):
"""Invokes the asynchronous function, surfacing the result through an
observable sequence.
Keyword arguments:
function_async -- {Function} Asynchronous function which returns a
Future to run.
Returns {Observable} An observable sequence exposing the function's
result value, or an exception."""
try:
future = function_async()
except Exception as ex:
return Observable.throw(ex)
return Observable.from_future(future)
示例12: skip_until
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def skip_until(self, other):
"""Returns the values from the source observable sequence only after
the other observable sequence produces a value.
other -- The observable sequence that triggers propagation of elements
of the source sequence.
Returns an observable sequence containing the elements of the source
sequence starting from the point the other sequence triggered
propagation.
"""
source = self
other = Observable.from_future(other)
def subscribe(observer):
is_open = [False]
def on_next(left):
if is_open[0]:
observer.on_next(left)
def on_completed():
if is_open[0]:
observer.on_completed()
subs = source.subscribe(on_next, observer.on_error, on_completed)
disposables = CompositeDisposable(subs)
right_subscription = SingleAssignmentDisposable()
disposables.add(right_subscription)
def on_next2(x):
is_open[0] = True
right_subscription.dispose()
def on_completed2():
right_subscription.dispose()
right_subscription.disposable = other.subscribe(on_next2, observer.on_error, on_completed2)
return disposables
return AnonymousObservable(subscribe)
示例13: on_next
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def on_next(inner_source):
if not has_current[0]:
has_current[0] = True
inner_source = Observable.from_future(inner_source)
inner_subscription = SingleAssignmentDisposable()
g.add(inner_subscription)
def on_completed_inner():
g.remove(inner_subscription)
has_current[0] = False
if is_stopped[0] and len(g) == 1:
observer.on_completed()
inner_subscription.disposable = inner_source.subscribe(
observer.on_next,
observer.on_error,
on_completed_inner
)
示例14: timeout
# 需要导入模块: from rx.observable import Observable [as 别名]
# 或者: from rx.observable.Observable import from_future [as 别名]
def timeout(self, duetime, other=None, scheduler=None):
"""Returns the source observable sequence or the other observable
sequence if duetime elapses.
1 - res = source.timeout(new Date()); # As a date
2 - res = source.timeout(5000); # 5 seconds
# As a date and timeout observable
3 - res = source.timeout(datetime(), rx.Observable.return_value(42))
# 5 seconds and timeout observable
4 - res = source.timeout(5000, rx.Observable.return_value(42))
# As a date and timeout observable
5 - res = source.timeout(datetime(), rx.Observable.return_value(42),
rx.Scheduler.timeout)
# 5 seconds and timeout observable
6 - res = source.timeout(5000, rx.Observable.return_value(42),
rx.Scheduler.timeout)
Keyword arguments:
:param datetime|int duetime: Absolute (specified as a datetime object) or
relative time (specified as an integer denoting milliseconds) when a
timeout occurs.
:param Observable other: Sequence to return in case of a timeout. If not
specified, a timeout error throwing sequence will be used.
:param Scheduler scheduler: Scheduler to run the timeout timers on. If not
specified, the timeout scheduler is used.
:returns: The source sequence switching to the other sequence in case of
a timeout.
:rtype: Observable
"""
scheduler_method = None
source = self
other = other or Observable.throw_exception(Exception("Timeout"))
other = Observable.from_future(other)
scheduler = scheduler or timeout_scheduler
if isinstance(duetime, datetime):
scheduler_method = scheduler.schedule_absolute
else:
scheduler_method = scheduler.schedule_relative
def subscribe(observer):
switched = [False]
_id = [0]
original = SingleAssignmentDisposable()
subscription = SerialDisposable()
timer = SerialDisposable()
subscription.disposable = original
def create_timer():
my_id = _id[0]
def action(scheduler, state=None):
switched[0] = (_id[0] == my_id)
timer_wins = switched[0]
if timer_wins:
subscription.disposable = other.subscribe(observer)
timer.disposable = scheduler_method(duetime, action)
create_timer()
def on_next(x):
on_next_wins = not switched[0]
if on_next_wins:
_id[0] += 1
observer.on_next(x)
create_timer()
def on_error(e):
on_error_wins = not switched[0]
if on_error_wins:
_id[0] += 1
observer.on_error(e)
def on_completed():
on_completed_wins = not switched[0]
if on_completed_wins:
_id[0] += 1
observer.on_completed()
original.disposable = source.subscribe(on_next, on_error, on_completed)
return CompositeDisposable(subscription, timer)
return AnonymousObservable(subscribe)