4 ms·
Hi, author here. Glad you've enjoyed the post! To answer your questions: As leshow pointed out, Rust uses the Result type to propagate errors. The way we'll in
by yoshuaw 7y ago
Hi, author here. Glad you've enjoyed the post! To answer your questions:
As leshow pointed out, Rust uses the Result type to propagate errors. The way we'll integrate this in parallel-stream is by adding `try_for_each`, `try_fold`, and `try_map` methods. These methods will short-circuit when an error is returned, and have counterparts in `std` and `async-std` already. One tricky part is to get cancellation right, but we already have a design for that, it's just a matter of implementing it now.
`async-std` comes with support for the `log` crate built-in, which provides information when a new `Task` (lightweight thread) is spawned. `parallel-stream` doesn't perform any logs on top of that, but it probably should! I'll open an issue.
Result sets can be generated through the `collect` method which calls the `FromParallelStream` trait. This can be implemented for various types, but common examples include: `Vec<T>`(generic array), `HashMap`, and `Result<Vec<T>>`. If you're interested in how this exactly works this post by jcoglan goes into incredible detail: https://blog.jcoglan.com/2019/04/22/generic-returns-in-rust https://blog.jcoglan.com/2019/04/22/generic-returns-in-rust
I hope this answers your questions!
- yazaddaruvala 7y agoGiven only the thread would die, what about panics? For example, `.parallel_stream().map(n => 1 / n)` What happens to the `n=0` case? Does parallel_stream propagate the panic, or replace the value with a Result::Err?
- yoshuaw 7y agoIt relies on async-std's behavior, which will propagate the panic.