-
Notifications
You must be signed in to change notification settings - Fork 957
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
Using Async Await? #61
Comments
i actually started investigating it in a branch somewhere once but i didn't finish it. the tricky bit is figuring out how far down the stack you are going to allow async/await to encroach. the pure domain code needs to be non-async, i would say. but what about the Repository and the UnitOfWork? Or the Service Layer? i didn't decide on a final answer for that... |
Theoretically it should be possible based on my understanding, it looks like the repository, service layer handlers to the entry points will be async and external calls awaited. Will investigate this further and document my findings here. |
Please see my refactoring: https://github.com/nomhoi/cosmicpython-fastapi |
There are many examples with asynchronous FastAPI for RealWorld project: |
Thanks for making efforts in this direction will definitely be on the look out to see how you implement this including the message_bus as async. Thank you for sharing. |
I intend to complete all chapters. |
All 13 chapters have been completed. |
Is the problem in this test? |
I am not sure. If I understood it right the problem is when you have a server that don't spin up one thread per request. The reason been that the |
this is awesome! well done :) if i get a bit more time, i want to investigate some more patterns around this. can we make it so that the repository is non-async somehow?? if you could somehow pre-load the state before entering the service layer, and have the outputs be some combination of state to modify (on a sqla session maybe?) plus events, then maybe the whole service layer could be sync somehow? it wouldn't work for the UoW, but, idk, the dream is, the fewer unit tests use async, the better. |
@hjwp why do you want a non-async? I am asking just because I am going full async on a project that I use the archit from your book. |
two reasons at the top of my mind:
|
I used in conftest.py: @pytest.fixture(scope="session")
def event_loop():
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close() Only one event loop will be created per a testing session: |
May be this will be usefull: https://returns.readthedocs.io/en/latest/pages/future.html |
Are derivatives/forks like the Fastapi one even legally allowed on github because the license is CC-By-ND? |
for the record, it's fine by me. i'll see what i can do about the license... |
Is it possible to use async await, especially when accessing external resources like the db?
The text was updated successfully, but these errors were encountered: