コード例 #1
0
ファイル: sink.py プロジェクト: aguil/RxPython
    def run(self, sources):
        self.isDisposed = False
        self.subscription = SerialDisposable()
        self.gate = AsyncLock()
        self.stack = []
        self.length = []

        self.stack.append(iter(sources))

        try:
            length = len(sources)
        except TypeError:
            self.length.append(-1)
        else:
            self.length.append(length)

        def scheduled(continuation):
            self.recurse = continuation
            self.gate.wait(self.moveNext)

        cancel = Scheduler.tailRecursion.scheduleRecursive(scheduled)

        return CompositeDisposable(
            self.subscription, cancel,
            Disposable.create(lambda: self.gate.wait(self.dispose)))
コード例 #2
0
    def schedulePeriodicWithState(self, state, interval, action):
        gate = AsyncLock()

        def gated():
            state = action(state)

        timer = PeriodicTimer(interval, lambda: gate.wait(gated))
        cancel = timer.start()

        return CompositeDisposable(cancel, gate)
コード例 #3
0
        def _scheduleCore(self, state, action):
            m = SingleAssignmentDisposable()

            def gated():
                if not m.isDisposed:
                    m.disposable = action(self, state)

            if self.gate == None:
                self.gate = AsyncLock()

            self.gate.wait(gated)

            return m
コード例 #4
0
        def _scheduleRelativeCore(self, state, dueTime, action):
            m = SingleAssignmentDisposable()
            now = Scheduler.now()

            def gated():
                if not m.isDisposed:
                    elapsed = Scheduler.now() - now
                    dt = Scheduler.normalize(dueTime - elapsed)

                    if dt > 0:
                        sleep(dt)

                    if not m.isDisposed:
                        m.disposable = action(self, state)

            if self.gate == None:
                self.gate = AsyncLock()

            self.gate.wait(gated)

            return m