Skip to content

Commit d1903be

Browse files
committed
add asyncio code to test
1 parent 0c31eda commit d1903be

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/example_async.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import httpx
3+
import asyncio
4+
5+
async def fetch(url):
6+
async with httpx.AsyncClient(verify=False, timeout=10.0) as client:
7+
r = await client.get(url)
8+
return r.text
9+
10+
async def main():
11+
urls = ["https://example.com", "https://python.org"]
12+
results = await asyncio.gather(*(fetch(u) for u in urls))
13+
print(results)
14+
15+
asyncio.run(main())

0 commit comments

Comments
 (0)