Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from h2non/feat-v2
feat(v0.2): new minor version + error behavioral changes
- Loading branch information
Showing
10 changed files
with
162 additions
and
80 deletions.
There are no files selected for viewing
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
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
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
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
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 paco | ||
import aiohttp | ||
|
||
|
||
async def fetch(url): | ||
async with aiohttp.ClientSession() as session: | ||
async with session.get(url) as res: | ||
return res | ||
|
||
|
||
async def fetch_urls(): | ||
urls = [ | ||
'https://www.google.com', | ||
'https://www.yahoo.com', | ||
'https://www.bing.com', | ||
'https://www.baidu.com', | ||
'https://duckduckgo.com', | ||
] | ||
|
||
# Map concurrent executor with concurrent limit of 3 | ||
responses = await paco.map(fetch, urls, limit=3) | ||
|
||
for res in responses: | ||
print('Status:', res.status) | ||
|
||
|
||
# Run in event loop | ||
paco.run(fetch_urls()) |
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 paco | ||
|
||
|
||
async def filterer(x): | ||
return x < 8 | ||
|
||
|
||
async def mapper(x): | ||
return x * 2 | ||
|
||
|
||
async def drop(x): | ||
return x < 10 | ||
|
||
|
||
async def reducer(acc, x): | ||
return acc + x | ||
|
||
|
||
async def task(numbers): | ||
return await (numbers | ||
| paco.filter(filterer) | ||
| paco.map(mapper) | ||
| paco.dropwhile(drop) | ||
| paco.reduce(reducer, initializer=0)) # noqa | ||
|
||
|
||
# Run in event loop | ||
number = paco.run(task((1, 2, 3, 4, 5, 6, 7, 8, 9, 10))) | ||
print('Number:', number) # => 36 |
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
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
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
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