我有一些代码,使用了scoped_threadpool,类似于这样:
extern crate scoped_threadpool;
use scoped_threadpool::Pool;
use std::error::Error;
fn main() {
inner_main().unwrap();
}
fn inner_main() -> Result<(), Box<Error>> {
let mut pool = Pool::new(2);
pool.scoped(|scope| {
scope.execute(move || {
// This changed to become fallible
fallible_code();
});
});
Ok(())
}
fn fallible_code() -> Result<(), Box<Error + Send + Sync>> {
Err(From::from("Failing"))
}
< p>最近fallible_code
函数更改为返回一个Result
,我想将错误从pool.scoped
块传播到外部。然而,Scope::execute
的签名不允许返回值:
fn execute<F>(&self, f: F)
where F: FnOnce() + Send + 'scope
我正在使用scoped_threadpool 0.1.7。
ret.map_err(|x| x as Box <Error>)
来匹配inner_main
的返回类型。 - Veedrac