From ec79c8bc1ef0c5880a40c7eb96dfece8544654e7 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 17 Jan 2025 17:31:55 -0500 Subject: [PATCH] Update README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 6165702..2c569c7 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,21 @@ int main(void) res.set_content(req.body, "text/plain"); }); + // If the handler takes time to finish, you can also poll the connection state + svr.Get("/task", [&](const Request& req, Response& res) { + const char * result = nullptr; + process.run(); // for example, starting an external process + while (result == nullptr) { + sleep(1); + if (req.is_connection_closed()) { + process.kill(); // kill the process + return; + } + result = process.stdout(); // != nullptr if the process finishes + } + res.set_content(result, "text/plain"); + }); + svr.Get("/stop", [&](const Request& req, Response& res) { svr.stop(); });