1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

Wait for spawned thread

A spawned thread doesn't block the main thread exiting unless explicitly joined.
The demo as written in the guide simply exits immediately at the moment.
This commit is contained in:
Robert Collins 2018-02-12 23:52:03 +13:00 committed by GitHub
parent 30bdf9cb5e
commit 232aba2080
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,13 +79,14 @@ fn index(req: HttpRequest) -> &'static str {
}
fn main() {
# thread::spawn(|| {
# let child = thread::spawn(|| {
HttpServer::new(
|| Application::new()
.resource("/", |r| r.f(index)))
.bind("127.0.0.1:8088").expect("Can not bind to 127.0.0.1:8088")
.run();
# });
});
# child.join().expect("failed to join server thread");
}
```