Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace coroutine decorator with async keyword #593

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions examples/asyncio/toasyncgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def on_next(value):

source.pipe(ops.materialize()).subscribe(on_next)

@asyncio.coroutine
def gen():
async def gen():
"""Generator producing futures"""
nonlocal future

Expand All @@ -50,8 +49,7 @@ def gen():
return _to_async_generator


@asyncio.coroutine
def go(loop):
async def go(loop):
scheduler = AsyncIOScheduler(loop)

xs = rx.from_([x for x in range(10)], scheduler=scheduler)
Expand All @@ -60,7 +58,7 @@ def go(loop):
# Wish we could write something like:
# ys = (x for x in yield from gen())
while True:
x = yield from gen()
x = await gen()
if x is None:
break
print(x)
Expand Down
12 changes: 4 additions & 8 deletions tests/test_observable/test_fromfuture.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def test_future_success(self):
loop = asyncio.get_event_loop()
success = [False, True, False]

@asyncio.coroutine
def go():
async def go():
future = Future()
future.set_result(42)

Expand All @@ -36,8 +35,7 @@ def test_future_failure(self):
loop = asyncio.get_event_loop()
success = [True, False, True]

@asyncio.coroutine
def go():
async def go():
error = Exception('woops')

future = Future()
Expand All @@ -63,8 +61,7 @@ def test_future_cancel(self):
loop = asyncio.get_event_loop()
success = [True, False, True]

@asyncio.coroutine
def go():
async def go():
future = Future()
source = rx.from_future(future)

Expand All @@ -87,8 +84,7 @@ def test_future_dispose(self):
loop = asyncio.get_event_loop()
success = [True, True, True]

@asyncio.coroutine
def go():
async def go():
future = Future()
future.set_result(42)

Expand Down
7 changes: 2 additions & 5 deletions tests/test_observable/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def test_start_async(self):
loop = asyncio.get_event_loop()
success = [False]

@asyncio.coroutine
def go():
async def go():
def func():
future = Future()
future.set_result(42)
Expand All @@ -40,8 +39,7 @@ def test_start_async_error(self):
loop = asyncio.get_event_loop()
success = [False]

@asyncio.coroutine
def go():
async def go():
def func():
future = Future()
future.set_exception(Exception(str(42)))
Expand Down Expand Up @@ -74,7 +72,6 @@ def func():

assert(done)


def test_start_func2(self):
scheduler = TestScheduler()

Expand Down
15 changes: 6 additions & 9 deletions tests/test_scheduler/test_eventloop/test_asyncioscheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def test_asyncio_schedule_now_units(self):
def test_asyncio_schedule_action(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
scheduler = AsyncIOScheduler(loop)
ran = False

Expand All @@ -36,16 +35,15 @@ def action(scheduler, state):

scheduler.schedule(action)

yield from asyncio.sleep(0.1)
await asyncio.sleep(0.1)
assert ran is True

loop.run_until_complete(go())

def test_asyncio_schedule_action_due(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
scheduler = AsyncIOScheduler(loop)
starttime = loop.time()
endtime = None
Expand All @@ -56,7 +54,7 @@ def action(scheduler, state):

scheduler.schedule_relative(0.2, action)

yield from asyncio.sleep(0.3)
await asyncio.sleep(0.3)
assert endtime is not None
diff = endtime - starttime
assert diff > 0.18
Expand All @@ -66,8 +64,7 @@ def action(scheduler, state):
def test_asyncio_schedule_action_cancel(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
ran = False
scheduler = AsyncIOScheduler(loop)

Expand All @@ -78,7 +75,7 @@ def action(scheduler, state):
d = scheduler.schedule_relative(0.05, action)
d.dispose()

yield from asyncio.sleep(0.3)
await asyncio.sleep(0.3)
assert ran is False

loop.run_until_complete(go())
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def test_asyncio_threadsafe_schedule_now_units(self):
def test_asyncio_threadsafe_schedule_action(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
scheduler = AsyncIOThreadSafeScheduler(loop)
ran = False

Expand All @@ -40,16 +39,15 @@ def schedule():

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

yield from asyncio.sleep(0.1)
await asyncio.sleep(0.1)
assert ran is True

loop.run_until_complete(go())

def test_asyncio_threadsafe_schedule_action_due(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
scheduler = AsyncIOThreadSafeScheduler(loop)
starttime = loop.time()
endtime = None
Expand All @@ -63,7 +61,7 @@ def schedule():

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

yield from asyncio.sleep(0.3)
await asyncio.sleep(0.3)
assert endtime is not None
diff = endtime - starttime
assert diff > 0.18
Expand All @@ -73,8 +71,7 @@ def schedule():
def test_asyncio_threadsafe_schedule_action_cancel(self):
loop = asyncio.get_event_loop()

@asyncio.coroutine
def go():
async def go():
ran = False
scheduler = AsyncIOThreadSafeScheduler(loop)

Expand All @@ -88,7 +85,7 @@ def schedule():

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

yield from asyncio.sleep(0.3)
await asyncio.sleep(0.3)
assert ran is False

loop.run_until_complete(go())
Expand All @@ -110,9 +107,8 @@ def thread_target():

test_body(scheduler, action, update_state)

@asyncio.coroutine
def go():
yield from asyncio.sleep(0.2)
async def go():
await asyncio.sleep(0.2)

loop.run_until_complete(go())

Expand Down