装饰器:等待功能后执行操作

问题描述 投票:1回答:1

我使用Python 3.7并具有以下装饰器:

def decorator(success_check: function):
    def wrap(func):
        async def inner(root, info, **args):
            func_result = await func(root, info, **args)
            if not success_check(func_result):
                pass # do some action
            return func(root, info, **args)
        return inner
    return wrap

在当前实现中,功能等待两次。我可以使它与等待过的func一起工作吗?

python python-3.x asynchronous decorator python-decorators
1个回答
1
投票

如果您呼叫return await func(root, info, **args),或者更好的话,只需执行return func_result,很可能会解决您的问题


0
投票

如果您呼叫return await func(root, info, **args),或者更好的话,只需执行return func_result,很可能会解决您的问题

© www.soinside.com 2019 - 2024. All rights reserved.