예제 #1
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True
            scheduler.schedule(action)

            yield from asyncio.sleep(0.1, loop=loop)
            assert ran is True
        def go():
            scheduler = AsyncIOScheduler(loop)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True
            scheduler.schedule(action)

            yield from asyncio.sleep(0.1, loop=loop)
            assert ran is True
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop)

            def action(scheduler, state):
                nonlocal ran
                ran = True
            d = scheduler.schedule_relative(0.05, action)
            d.dispose()

            yield from asyncio.sleep(0.3, loop=loop)
            assert not ran
예제 #4
0
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop)

            def action(scheduler, state):
                nonlocal ran
                ran = True
            d = scheduler.schedule_relative(0.010, action)
            d.dispose()

            yield from asyncio.sleep(0.1, loop=loop)
            assert(not ran)
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            scheduler.schedule_relative(0.2, action)

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime - starttime
            assert diff > 0.18
예제 #6
0
        def go():
            scheduler = AsyncIOScheduler(loop)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            scheduler.schedule_relative(0.2, action)

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime-starttime
            assert diff > 0.18
예제 #7
0
 def test_asyncio_schedule_now_units(self):
     loop = asyncio.get_event_loop()
     scheduler = AsyncIOScheduler(loop)
     diff = scheduler.now
     yield from asyncio.sleep(0.1, loop=loop)
     diff = scheduler.now - diff
     assert timedelta(milliseconds=80) < diff < timedelta(milliseconds=180)
예제 #8
0
    def open(self):
        scheduler = AsyncIOScheduler()

        print("WebSocket opened")

        # A Subject is both an observable and observer, so we can both subscribe
        # to it and also feed (send) it with new values
        self.subject = Subject()

        # Get all distinct key up events from the input and only fire if long enough and distinct
        searcher = self.subject.pipe(
            ops.map(lambda x: x["term"]),
            ops.filter(lambda text: len(text) > 2
                       ),  # Only if the text is longer than 2 characters
            ops.debounce(0.750),  # Pause for 750ms
            ops.distinct_until_changed(),  # Only if the value has changed
            ops.flat_map_latest(search_wikipedia))

        def send_response(x):
            self.write_message(x.body)

        def on_error(ex):
            print(ex)

        searcher.subscribe(send_response, on_error, scheduler=scheduler)
예제 #9
0
async def setup(app):
    app["scheduler"] = sched = AsyncIOScheduler()
    app["subject"] = subject = rx.subjects.Subject()

    subject.pipe(
        ops.map(lambda x: (b64decode(x[0]), x[1])),
        ops.map(lambda x: (int.from_bytes(x[0], "big", signed=False), x[1])),
    ).subscribe_(on_next=(lambda x: asyncio.create_task(crc(x[0], x[1]))),
                 on_error=print)
예제 #10
0
        def go():
            scheduler = AsyncIOScheduler(loop, threadsafe=True)
            ran = False

            def action(scheduler, state):
                nonlocal ran
                ran = True

            def schedule():
                scheduler.schedule(action)

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.1, loop=loop)
            assert ran is True
예제 #11
0
        def go():
            ran = False
            scheduler = AsyncIOScheduler(loop, threadsafe=True)

            def action(scheduler, state):
                nonlocal ran
                ran = True

            def schedule():
                d = scheduler.schedule_relative(0.010, action)
                d.dispose()

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.1, loop=loop)
            assert(not ran)
예제 #12
0
        def go():
            scheduler = AsyncIOScheduler(loop, threadsafe=True)
            starttime = loop.time()
            endtime = None

            def action(scheduler, state):
                nonlocal endtime
                endtime = loop.time()

            def schedule():
                scheduler.schedule_relative(0.2, action)

            threading.Thread(target=schedule).start()

            yield from asyncio.sleep(0.3, loop=loop)
            diff = endtime-starttime
            assert diff > 0.18
예제 #13
0
    def test_asyncio_schedule_now(self):
        loop = asyncio.get_event_loop()
        scheduler = AsyncIOScheduler(loop)
        res = scheduler.now - datetime.now()

        assert res < timedelta(seconds=1)
예제 #14
0
 def test_asyncio_schedule_now(self):
     loop = asyncio.get_event_loop()
     scheduler = AsyncIOScheduler(loop)
     diff = scheduler.now - datetime.utcfromtimestamp(loop.time())
     assert abs(diff) < timedelta(milliseconds=1)