Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to extend server lifetime. #27

Open
Parakleta opened this issue Nov 10, 2015 · 1 comment
Open

Document how to extend server lifetime. #27

Parakleta opened this issue Nov 10, 2015 · 1 comment

Comments

@Parakleta
Copy link

The example on the front page never prints "On 3000" because the lifetime of the Listening returned from http().unwrap() expires within its own statement and then blocks the program. The solution to this is to store this value in an unused variable so that its lifetime is extended until the end of the block.

For example:

let _listener = Iron::new(hello_world).http("localhost:3000").unwrap();

The leading _ suppresses unused variable warnings (but note that it cannot just be called _ since that has no lifetime).

It would also be good to add a note to the Iron.http and Iron.https methods where they discuss the guard to explain how to prevent it blocking.

@Parakleta
Copy link
Author

Note that I have discovered that

let _ = &Iron::new(hello_world).http("localhost:3000").unwrap();

also works. I'm not sure which of the two should be considered idiomatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant