Ejemplo n.º 1
0
def publishLast(self, selector=None):
    assert isinstance(self, Observable)

    if selector == None:
        return self.multicast(AsyncSubject())
    else:
        assert callable(selector)

        return self.multicastIndividual(lambda: AsyncSubject(), selector)
Ejemplo n.º 2
0
    def wrapper(*args) -> Observable:
        subject = AsyncSubject()

        def action(scheduler, state):
            try:
                result = func(*args)
            except Exception as ex:  # pylint: disable=broad-except
                subject.on_error(ex)
                return

            subject.on_next(result)
            subject.on_completed()

        _scheduler.schedule(action)
        return subject.pipe(ops.as_observable())
Ejemplo n.º 3
0
def start(action, scheduler=Scheduler.default):
  assert isinstance(scheduler, Scheduler)

  subject = AsyncSubject()

  def scheduled():
    try:
      subject.onNext(action())
      subject.onCompleted()
    except Exception as e:
      subject.onError(e)

    return Disposable.empty()

  scheduler.schedule(scheduled)

  return subject.asObservable()
Ejemplo n.º 4
0
def start(action, scheduler=Scheduler.default):
    assert isinstance(scheduler, Scheduler)

    subject = AsyncSubject()

    def scheduled():
        try:
            subject.onNext(action())
            subject.onCompleted()
        except Exception as e:
            subject.onError(e)

        return Disposable.empty()

    scheduler.schedule(scheduled)

    return subject.asObservable()
Ejemplo n.º 5
0
def fromFuture(future):
    subject = AsyncSubject()

    def callback(f):
        if f.cancelled():
            subject.onError(FutureCanceledException())
        elif f.exception() != None:
            subject.onError(f.exception())
        else:
            subject.onNext(f.result())
            subject.onCompleted()

    if future.done():
        callback(future)
    else:
        future.add_done_callback(callback)

    return subject
Ejemplo n.º 6
0
 def action1(scheduler, state=None):
     subject[0] = AsyncSubject()
Ejemplo n.º 7
0
# ReplaySubject会缓存所有值,如果指定参数的话只会缓存最近的几个值
print('--------ReplaySubject---------')
subject = ReplaySubject()
subject.on_next(1)
subject.subscribe(lambda i: print(i))
subject.on_next(2)
subject.on_next(3)
subject.on_next(4)
subject.on_completed()

# BehaviorSubject会缓存上次发射的值,除非Observable已经关闭
print('--------BehaviorSubject---------')
subject = BehaviorSubject(0)
subject.on_next(1)
subject.on_next(2)
subject.subscribe(lambda i: print(i))
subject.on_next(3)
subject.on_next(4)
subject.on_completed()

# AsyncSubject会缓存上次发射的值,而且仅会在Observable关闭后开始发射
print('--------AsyncSubject---------')
subject = AsyncSubject()
subject.on_next(1)
subject.on_next(2)
subject.subscribe(lambda i: print(i))
subject.on_next(3)
subject.on_next(4)
subject.on_completed()
Ejemplo n.º 8
0
def KeyPress(observable: AsyncSubject):
    observable.subscribe(lambda key: PressKeyWin(winKeyWords[key]),
     on_next = lambda: ReleaseKeyWin(),
     on_completed =  lambda: ReleaseKeyWin())