Created
November 3, 2022 11:40
-
-
Save egeromin/6348ed27debf510215266e07e7c5309e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import asyncio | |
from collections import defaultdict | |
from async_lru import alru_cache | |
num_email_confirmations = defaultdict(int) | |
@alru_cache(maxsize=500) | |
async def send_email_confirmation(user_email: str) -> int: | |
num_email_confirmations[user_email] += 1 | |
await asyncio.sleep(1) | |
return num_email_confirmations[user_email] | |
async def send_confirmations() -> int: | |
send_once = asyncio.create_task(send_email_confirmation("[email protected]")) | |
send_again = asyncio.create_task(send_email_confirmation("[email protected]")) | |
await send_once | |
return await send_again | |
def main(): | |
result = asyncio.run(send_confirmations()) | |
assert result == 1 | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment