Using a coroutine as decorator

Thanks to @blacknght’s comment, considering

def foo():
    def wrapper(func):
        @functools.wraps(func)
        async def wrapped(*args):
             # Some fancy foo stuff
            return await func(*args)
        return wrapped
    return wrapper

and

def boo():
    def wrapper(func):
        @functools.wraps(func)
        async def wrapped(*args):
            # Some fancy boo stuff
            return await func(*args)
        return wrapped
    return wrapper

as two decorators, and

@foo()
@boo()
async def work(*args):
    pass

As the foo is wrapping the work coroutine, the key is to await the func(*arg) in both decorators.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)