diff --git a/specs/lifespan.rst b/specs/lifespan.rst index d47c5830..da27c90c 100644 --- a/specs/lifespan.rst +++ b/specs/lifespan.rst @@ -18,15 +18,15 @@ A possible implementation of this protocol is given below:: async def app(scope, receive, send): if scope['type'] == 'lifespan': - 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 + message = await receive() + assert message['type'] == 'lifespan.startup' + ... # Do some startup here! + await send({'type': 'lifespan.startup.complete'}) + + message = await receive() + assert message['type'] == 'lifespan.shutdown' + ... # Do some shutdown here! + await send({'type': 'lifespan.shutdown.complete'}) else: pass # Handle other types