Post-hook a function, post-process and pass through all returns

不羁的心 提交于 2019-12-02 04:19:34

You don't need the closure. func is called before calling your closure generator anyway. You just need a function that passes its arguments straight through to its return values to give you a hook point for your second tag:

function passthrough_return(tag, ...)
    metric2[tag] = os.time()
    return ...
end

function passthrough(tag, func, ...)
    metric1[tag] = os.time()
    return passthrough_return(tag, func(...))
end

You're still getting the overhead of an extra function call, but that's better than creating a closure or a table and far less than the overhead of your pre/post processing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!