include: co/defer.h.


defer is a macro provided by CO, which is similar to defer in golang.

#include "co/defer.h"
#include "co/time.h"
#include "co/log.h"
#include "co/json.h"

void f(const Json& req, Json& res) {
    Timer t;
    LOG << "req: " << req;
    defer(LOG << "res: " << res << ", time elapse: " << << "us");

    // do something here

In the above example, the code in defer will be executed at the end of the function f, thus printing the output and time elapse of the function.