We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 80f1988 commit ec79c8bCopy full SHA for ec79c8b
README.md
@@ -125,6 +125,21 @@ int main(void)
125
res.set_content(req.body, "text/plain");
126
});
127
128
+ // If the handler takes time to finish, you can also poll the connection state
129
+ svr.Get("/task", [&](const Request& req, Response& res) {
130
+ const char * result = nullptr;
131
+ process.run(); // for example, starting an external process
132
+ while (result == nullptr) {
133
+ sleep(1);
134
+ if (req.is_connection_closed()) {
135
+ process.kill(); // kill the process
136
+ return;
137
+ }
138
+ result = process.stdout(); // != nullptr if the process finishes
139
140
+ res.set_content(result, "text/plain");
141
+ });
142
+
143
svr.Get("/stop", [&](const Request& req, Response& res) {
144
svr.stop();
145
0 commit comments