本文整理汇总了Python中rx.core.Observable.defer方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.defer方法的具体用法?Python Observable.defer怎么用?Python Observable.defer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rx.core.Observable
的用法示例。
在下文中一共展示了Observable.defer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: time_interval
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def time_interval(self, scheduler):
"""Records the time interval between consecutive values in an
observable sequence.
1 - res = source.time_interval();
2 - res = source.time_interval(Scheduler.timeout)
Keyword arguments:
scheduler -- [Optional] Scheduler used to compute time intervals. If
not specified, the timeout scheduler is used.
Return An observable sequence with time interval information on values.
"""
source = self
scheduler = scheduler or timeout_scheduler
def defer():
last = [scheduler.now]
def selector(x):
now = scheduler.now
span = now - last[0]
last[0] = now
return TimeInterval(value=x, interval=span)
return source.map(selector)
return Observable.defer(defer)
示例2: observable_timer_timespan_and_period
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def observable_timer_timespan_and_period(duetime, period, scheduler):
if duetime == period:
def subscribe(observer):
def action(count):
observer.on_next(count)
return count + 1
return scheduler.schedule_periodic(period, action, state=0)
return AnonymousObservable(subscribe)
def defer():
dt = scheduler.now + scheduler.to_timedelta(duetime)
return observable_timer_date_and_period(dt, period, scheduler)
return Observable.defer(defer)
示例3: repeat
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def repeat(self, repeat_count=None):
"""Repeats the observable sequence a specified number of times. If the
repeat count is not specified, the sequence repeats indefinitely.
1 - repeated = source.repeat()
2 - repeated = source.repeat(42)
Keyword arguments:
repeat_count -- Number of times to repeat the sequence. If not
provided, repeats the sequence indefinitely.
Returns the observable sequence producing the elements of the given
sequence repeatedly."""
return Observable.defer(lambda: Observable.concat(Enumerable.repeat(self, repeat_count)))
示例4: many_select
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def many_select(self, selector, scheduler=None):
"""Comonadic bind operator. Internally projects a new observable for each
value, and it pushes each observable into the user-defined selector function
that projects/queries each observable into some result.
Keyword arguments:
selector -- {Function} A transform function to apply to each element.
scheduler -- {Object} [Optional] Scheduler used to execute the
operation. If not specified, defaults to the ImmediateScheduler.
Returns {Observable} An observable sequence which results from the
comonadic bind operation.
"""
scheduler = scheduler or immediate_scheduler
source = self
def factory():
chain = [None]
def mapper(x):
curr = ChainObservable(x)
chain[0] and chain[0].on_next(x)
chain[0] = curr
return curr
def on_error(e):
if chain[0]:
chain[0].on_error(e)
def on_completed():
if chain[0]:
chain[0].on_completed()
return source.map(
mapper
).tap(
noop, on_error, on_completed
).observe_on(
scheduler
).map(
selector
)
return Observable.defer(factory)
示例5: test_ref_count_notconnected
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def test_ref_count_notconnected(self):
disconnected = [False]
count = [0]
def factory():
count[0] += 1
def create(obs):
def func():
disconnected[0] = True
return func
return Observable.create(create)
xs = Observable.defer(factory)
subject = MySubject()
conn = ConnectableObservable(xs, subject)
refd = conn.ref_count()
dis1 = refd.subscribe()
self.assertEqual(1, count[0])
self.assertEqual(1, subject.subscribe_count)
assert(not disconnected[0])
dis2 = refd.subscribe()
self.assertEqual(1, count[0])
self.assertEqual(2, subject.subscribe_count)
assert(not disconnected[0])
dis1.dispose()
assert(not disconnected[0])
dis2.dispose()
assert(disconnected[0])
disconnected[0] = False
dis3 = refd.subscribe()
self.assertEqual(2, count[0])
self.assertEqual(3, subject.subscribe_count)
assert(not disconnected[0])
dis3.dispose()
assert(disconnected[0])
示例6: observable_delay_date
# 需要导入模块: from rx.core import Observable [as 别名]
# 或者: from rx.core.Observable import defer [as 别名]
def observable_delay_date(source, duetime, scheduler):
def defer():
timespan = scheduler.to_datetime(duetime) - scheduler.now
return observable_delay_timespan(source, timespan, scheduler)
return Observable.defer(defer)