forked from orbit-oss/flask
Add async support
This allows for async functions to be passed to the Flask class
instance, for example as a view function,
@app.route("/")
async def index():
return "Async hello"
this comes with a cost though of poorer performance than using the
sync equivalent.
asgiref is the standard way to run async code within a sync context,
and is used in Django making it a safe and sane choice for this.
This commit is contained in:
parent
85b8fab268
commit
6979265fa6
11 changed files with 165 additions and 9 deletions
|
|
@ -1050,7 +1050,7 @@ class Flask(Scaffold):
|
|||
"View function mapping is overwriting an existing"
|
||||
f" endpoint function: {endpoint}"
|
||||
)
|
||||
self.view_functions[endpoint] = view_func
|
||||
self.view_functions[endpoint] = self.ensure_sync(view_func)
|
||||
|
||||
@setupmethod
|
||||
def template_filter(self, name=None):
|
||||
|
|
@ -1165,7 +1165,7 @@ class Flask(Scaffold):
|
|||
|
||||
.. versionadded:: 0.8
|
||||
"""
|
||||
self.before_first_request_funcs.append(f)
|
||||
self.before_first_request_funcs.append(self.ensure_sync(f))
|
||||
return f
|
||||
|
||||
@setupmethod
|
||||
|
|
@ -1198,7 +1198,7 @@ class Flask(Scaffold):
|
|||
|
||||
.. versionadded:: 0.9
|
||||
"""
|
||||
self.teardown_appcontext_funcs.append(f)
|
||||
self.teardown_appcontext_funcs.append(self.ensure_sync(f))
|
||||
return f
|
||||
|
||||
@setupmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue