[Docs] Lifespan ref implementation
See original GitHub issueHi everyone. Looking at https://asgi.readthedocs.io/en/latest/specs/lifespan.html , I saw the following example implementation of the lifespan
type.
while True:
message = await receive()
if message['type'] == 'lifespan.startup':
... # Do some startup here!
await send({'type': 'lifespan.startup.complete'})
elif message['type'] == 'lifespan.shutdown':
... # Do some shutdown here!
await send({'type': 'lifespan.shutdown.complete'})
return
My naive implementation would consist of four flat lines of code only (receive, send, receive, send).
What is the reason for the while True
loop and the fail-safe message handling here? It’s seems like I am missing something.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Object Lifecycle Management | Cloud Storage
Introduction · Downgrade the storage class of objects older than 365 days to Coldline storage. · Delete objects created before January 1, 2019....
Read more >Validating References with Lifetimes - The Rust Programming ...
Most people use the name 'a for the first lifetime annotation. We place lifetime parameter annotations after the & of a reference, using...
Read more >Best practices for Cloud Firestore - Firebase
To implement parallel reads as you migrate traffic to a new collection, read from the old collection first. If the document is missing,...
Read more >Dependency injection guidelines - .NET | Microsoft Learn
The app requires an IDisposable instance with a transient lifetime for either of the following scenarios: ... Use the factory pattern to create...
Read more >Automatic Reference Counting - Documentation - Swift.org
The instances can then refer to each other without creating a strong reference cycle. Use a weak reference when the other instance has...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, you’re right, sorry - the loop should be outside the if statement there. That does need fixing!
I get the feeling, we might be talking past each other. This is the complete code example from the docs:
As I understand it, the highlighted loop (
while True
) is just for the lifespan protocol, which only contains two message types to be received and processed in this order.So, my suggestion is the following:
Am I missing something here?