How to use the asgiref.compatibility.guarantee_single_callable function in asgiref

To help you get started, we’ve selected a few asgiref examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github django / asgiref / asgiref / testing.py View on Github external
def __init__(self, application, scope):
        self.application = guarantee_single_callable(application)
        self.scope = scope
        self.input_queue = asyncio.Queue()
        self.output_queue = asyncio.Queue()
        self.future = asyncio.ensure_future(
            self.application(scope, self.input_queue.get, self.output_queue.put)
        )
github ericls / django-simple-task / django_simple_task / middleware.py View on Github external
if message["type"] == "lifespan.startup":
                    workers = [
                        create_task(worker(str(i), queue))
                        for i in range(
                            int(getattr(settings, "DJANGO_SIMPLE_TASK_WORKERS", 1))
                        )
                    ]
                    await send({"type": "lifespan.startup.complete"})
                elif message["type"] == "lifespan.shutdown":
                    await queue.join()
                    for w in workers:
                        w.cancel()
                    await send({"type": "lifespan.shutdown.complete"})
                    break
        else:
            return await guarantee_single_callable(app)(scope, receive, send)