Ideas for Result/Error handling #1132
antonWetzel
started this conversation in
Ideas
Replies: 1 comment
-
I think chunks.into_par_iter().try_for_each_init(
|| Some(std::fs::File::open(&path)),
|file, (chunk_start, chunk_length)| {
let file = match file {
Some(Ok(file)) => file, // use it!
Some(Err(_)) => file.take().unwrap()?, // steal the option and return its inner error
None => unreachable!(), // we shouldn't be called again after an error
};
// Now just return the computation's Result
expensive_computation(file, chunk_start, chunk_length)
},
)
We don't have a way to pass a borrowed reference as a regular |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
I got a file with independant chunks and want to do an expensive computation for every chunk.
Now I want to handle the errors by returning, when an error occurs.
Trying to handle the errors
The error with the computations can be catched with an
map
instead offor_each
The error in the
init
is hard to catch, because it is always owned by rayon, not my code.Questions
Solutions?
(Note: concepts which may clash with rayon internals or other limitations)
For the computation
Let tasks without a return value return a generic
TaskResult
The
for_each
would check theTaskResult
and maybe cancel. I hope this does not generate overhead for()
.For the init
The
Result<_, Init>
and the genericInit
value can't be differentiated easily, so I don't see an easy solution.It would be cool if the
..._with_init
would be just awith_init
methodand then maybe an
error_filter
, which collects the first encountered errorBeta Was this translation helpful? Give feedback.
All reactions