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
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
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
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)
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)
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)
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
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)
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
def test_asyncio_schedule_now(self): loop = asyncio.get_event_loop() scheduler = AsyncIOScheduler(loop) res = scheduler.now - datetime.now() assert res < timedelta(seconds=1)
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)