Skip to content

Commit ec79c8b

Browse files
committed
Update README
1 parent 80f1988 commit ec79c8b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ int main(void)
125125
res.set_content(req.body, "text/plain");
126126
});
127127

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+
128143
svr.Get("/stop", [&](const Request& req, Response& res) {
129144
svr.stop();
130145
});

0 commit comments

Comments
 (0)