-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add source code for examples in docs
- Loading branch information
Showing
20 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import time | ||
|
||
import anyio | ||
|
||
|
||
def do_sync_work(name: str): | ||
time.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
async def main(): | ||
message = do_sync_work(name="World") | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import time | ||
|
||
import anyio | ||
from asyncer import asyncify | ||
|
||
|
||
def do_sync_work(name: str): | ||
time.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
async def main(): | ||
message = await asyncify(do_sync_work)(name="World") | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import anyio | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
async def main(): | ||
message = await do_work(name="World") | ||
return message | ||
|
||
|
||
result = anyio.run(main) | ||
print(result) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import anyio | ||
import asyncer | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
async def main(name: str): | ||
result = await do_work(name=name) | ||
return result | ||
|
||
|
||
result = asyncer.runnify(main)(name="World") | ||
print(result) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import anyio | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
print(f"Hello, {name}") | ||
|
||
|
||
async def get_data(): | ||
await do_work(name="Yury") | ||
await do_work(name="Nathaniel") | ||
await do_work(name="Alex") | ||
|
||
|
||
async def main(): | ||
await get_data() | ||
|
||
|
||
anyio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import anyio | ||
import asyncer | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
print(f"Hello, {name}") | ||
|
||
|
||
async def get_data(): | ||
async with asyncer.create_task_group() as task_group: | ||
task_group.soonify(do_work)(name="Yury") | ||
task_group.soonify(do_work)(name="Nathaniel") | ||
task_group.soonify(do_work)(name="Alex") | ||
|
||
|
||
async def main(): | ||
await get_data() | ||
|
||
|
||
anyio.run(main) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import anyio | ||
import asyncer | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
message = f"Hello, {name}" | ||
return message | ||
|
||
|
||
async def get_data(): | ||
async with asyncer.create_task_group() as task_group: | ||
soon_value1 = task_group.soonify(do_work)(name="Yury") | ||
soon_value2 = task_group.soonify(do_work)(name="Nathaniel") | ||
soon_value3 = task_group.soonify(do_work)(name="Alex") | ||
|
||
data = [soon_value1.value, soon_value2.value, soon_value3.value] | ||
return data | ||
|
||
|
||
async def main(): | ||
data = await get_data() | ||
for message in data: | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import anyio | ||
import asyncer | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
message = f"Hello, {name}" | ||
return message | ||
|
||
|
||
async def get_data(): | ||
async with asyncer.create_task_group() as task_group: | ||
soon_value1 = task_group.soonify(do_work)(name="Yury") | ||
soon_value2 = task_group.soonify(do_work)(name="Nathaniel") | ||
soon_value3 = task_group.soonify(do_work)(name="Alex") | ||
print(soon_value1.value) | ||
|
||
data = [soon_value1.value, soon_value2.value, soon_value3.value] | ||
return data | ||
|
||
|
||
async def main(): | ||
data = await get_data() | ||
for message in data: | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import anyio | ||
import asyncer | ||
|
||
|
||
async def do_work(name: str): | ||
await anyio.sleep(1) | ||
message = f"Hello, {name}" | ||
return message | ||
|
||
|
||
async def get_data(): | ||
async with asyncer.create_task_group() as task_group: | ||
soon_value1 = task_group.soonify(do_work)(name="Yury") | ||
await anyio.sleep(2) | ||
if soon_value1.ready: | ||
print(f"Preview value1: {soon_value1.value}") | ||
soon_value2 = task_group.soonify(do_work)(name="Nathaniel") | ||
soon_value3 = task_group.soonify(do_work)(name="Alex") | ||
|
||
data = [soon_value1.value, soon_value2.value, soon_value3.value] | ||
return data | ||
|
||
|
||
async def main(): | ||
data = await get_data() | ||
for message in data: | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import time | ||
|
||
import anyio | ||
from asyncer import asyncify, syncify | ||
|
||
|
||
async def do_async_work(name: str): | ||
await anyio.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
def do_sync_work(name: str): | ||
time.sleep(1) | ||
message = syncify(do_async_work)(name=name) | ||
return message | ||
|
||
|
||
async def main(): | ||
message = await asyncify(do_sync_work)(name="World") | ||
print(message) | ||
|
||
|
||
anyio.run(main) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import time | ||
|
||
import anyio | ||
from asyncer import asyncify, syncify | ||
|
||
|
||
async def do_async_work(name: str): | ||
await anyio.sleep(1) | ||
return f"Hello, {name}" | ||
|
||
|
||
def do_sync_work(name: str): | ||
time.sleep(1) | ||
message = syncify(do_async_work, raise_sync_error=False)(name=name) | ||
return message | ||
|
||
|
||
async def main(): | ||
message = await asyncify(do_sync_work)(name="World") | ||
print(message) | ||
|
||
|
||
def sync_main(): | ||
message = do_sync_work(name="Sync World") | ||
print(message) | ||
|
||
|
||
anyio.run(main) | ||
sync_main() |