Skip to content

Document how to extend server lifetime. #27

@Parakleta

Description

@Parakleta

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions