为什么这个示例铁代码似乎会阻塞?

Why does this example iron code seem to block?

我是 运行 来自 http://ironframework.io 主页的 hello world 示例代码:

extern crate iron;

use iron::prelude::*;
use iron::status;

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }

    Iron::new(hello_world).http("localhost:3000").unwrap();
    println!("On 3000");
}

我希望看到 "On 3000" 出现在标准输出中,但它从未出现。我的猜测是主线程在执行 println 之前被阻塞了。为什么会这样?

如果我使用临时文件并在之后调用 unwrap,我会得到预期的输出:

fn main() {
    fn hello_world(_: &mut Request) -> IronResult<Response> {
        Ok(Response::with((status::Ok, "Hello World!")))
    }

    let result = Iron::new(hello_world).http("localhost:3000");
    println!("On 3000");
    result.unwrap();
}

为什么在 return 值上调用 unwrap 时行为会发生变化?

我是 运行 铁锈 1.1.0 和铁 0.1.20。

写完问题后突然想到答案

http 函数 returns 和 HttpResult<Listening> Listening 类型有一个在线程上调用 join 的析构函数,它会阻塞。

在第一种情况下,返回对象的生命周期在调用 unwrap 后完成,因此调用析构函数加入线程。如果我将它分配给一个变量,析构函数直到调用 unwrap 之后才会被调用。