weibeu / Flask-Discord

Discord OAuth2 extension for Flask. An Easier implementation of "Log In With Discord".
https://flask-discord.readthedocs.io/en/latest/
MIT License
182 stars 47 forks source link

Flask[async] compatibility #72

Open tdev-be opened 1 year ago

tdev-be commented 1 year ago

use a coroutine if we are in async mode

Space-Banane commented 1 year ago

@tdev-be Thanks, this code works well. Could you make a repo with this already merged? I want to install it that way!

Guddi8 commented 1 year ago

Flask mentions here https://flask.palletsprojects.com/en/2.0.x/async-await/#extensions to use the ensure_sync function for extensions, like this:

def extension(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        ...  # Extension logic
        return current_app.ensure_sync(func)(*args, **kwargs)

    return wrapper

Havent testes it yet, but Im sure it works. I guess this should be used instead, there might be a good reason to not just await the view.