Biraz böyle scoped_threadpool kullanan bazı kod var: fallible_code
işlevi son zamanlarda Result
dönmek değiştiBir scoped_threadpool iş parçacığındaki bir hatayı nasıl döndürebilirim?
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"))
}
ve ben pool.scoped
bloğunun dışında hatayı yaymak istiyorum. Ancak, Scope::execute
imzası dönüş değeri için izin vermez: Ben scoped_threadpool 0.1.7 kullanıyorum
fn execute<F>(&self, f: F)
where F: FnOnce() + Send + 'scope
.
Fikir kulağa hoş geliyor, ancak 'Sync' değil mi? –
@MatthieuM. Bu, 'inner_main'nin dönüş türüyle eşleşmesi için ret.map_err (| x | x Box)' un gerekli olmasının nedeni budur. –
Veedrac